I don’t know why the variable is correctly updated within that if block, and the result is visible using a print, but outside the variable nothing seems to happen. I suppose that the issue is related to scopes, since it seems last_dialing_number is created only locally.
def serial_digest(lock):
...
last_dialing_number = 0
with GSM(lock=lock) as g:
while True:
if g.data_not_available():
continue
data = g.receive()
call_status = ''
if data == 'RING':
call_status='Ring'
g.transceive('AT+CLCCrn')
data = g.receive()
if data.startswith('+CLCC'):
for x in data[len('+CLCC: '):].split(','):
if x.startswith('"') and x.endswith('"'):
print(last_dialing_number) # correct value
last_dialing_number = x.strip('"')
print(last_dialing_number) # incorrect value