Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Pythonista doesn't catch SystemExit exception

Open pietvo opened this issue 1 year ago • 3 comments
trafficstars

The following python script gives the expected output on Python 3.10 (and other versions) on MacOS, but not in Pythonista 3 (version 3.4).


import sys

print('''
This should print:
Start
Caught SystemExit:  Test
After Exit
''')


try:
    print('Start')
    sys.exit('Test')
    print('This should not be printed')
except SystemExit as e:
    print('Caught SystemExit: ', e)
print('After Exit')

If SystemExit is replaced by BaseException, it works.

pietvo avatar Oct 31 '24 18:10 pietvo

Use KeyboardInterrupt instead of SystemExit.

except (KeyboardInterrupt, SystemExit) as e:

cclauss avatar Oct 31 '24 19:10 cclauss

Does that mean that in Pythonista sys.exit() is treated like a keyboard interrupt (control-c)?

pietvo avatar Oct 31 '24 20:10 pietvo

iOS does not really allow apps to shutdown so Pythonista cannot behave exactly like Python on desktop operating systems.

cclauss avatar Oct 31 '24 20:10 cclauss