omz / Pythonista-Issues

Issue tracker for Pythonista (iOS)
169 stars 14 forks source link

Pythonista doesn't catch SystemExit exception #750

Open pietvo opened 1 month ago

pietvo commented 1 month ago

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.

cclauss commented 1 month ago

Use KeyboardInterrupt instead of SystemExit.

except (KeyboardInterrupt, SystemExit) as e:
pietvo commented 1 month ago

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

cclauss commented 1 month ago

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