Pythonista-Issues
Pythonista-Issues copied to clipboard
`exit()` crashes pythonista
When calling exit(), whether in script or console, the app crashes with no modification to file saved. This is also true for raise SystemExit or quit().
Expected behavior: the script which call exit() exits (or do nothing when called in console), and app stays running (like old version of pythonista do).
>>> import platform
>>> platform.version()
'Darwin Kernel Version 22.1.0: Thu Oct 6 19:34:09 PDT 2022; root:xnu-8792.42.7~1/RELEASE_ARM64_T8110'
>>> platform.iOS_ver()
('iOS', '16.1.1')
>>> platform.python_version()
'3.10.4'
Same situation for me!
Found a solution by using sys.exit().
Run the code linter that is built into Pythonista. https://docs.astral.sh/ruff/rules/sys-exit-alias
Run the code linter that is built into Pythonista. https://docs.astral.sh/ruff/rules/sys-exit-alias
How can this help with exit() crashes?
The linter should fail when it sees exit() and tell you to use sys.exit() instead.
Can we close this issue given that we have an effective workaround?
Although sys.exit provides a workaround, the exit still crashes the app. This is quite unexpected, and may cause losing file or data.
(think of you are using PyCharm to debug a script, and an exit() call terminates the PyCharm.)
If this is by design, maybe should be better provided by package pythonista or editor
Even if the linter provide a warning about exit() calls, it is not so cool, to deal with unexpected crashes. And for example I am not actively using linter tool. Will be a label assigned to this issue? Thank you in advance for fixing this!