Pythonista-Issues
Pythonista-Issues copied to clipboard
Pythonista doesn't catch SystemExit exception
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.
Use KeyboardInterrupt instead of SystemExit.
except (KeyboardInterrupt, SystemExit) as e:
Does that mean that in Pythonista sys.exit() is treated like a keyboard interrupt (control-c)?
iOS does not really allow apps to shutdown so Pythonista cannot behave exactly like Python on desktop operating systems.