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

`exit()` crashes pythonista

Open imkzh opened this issue 2 years ago • 6 comments
trafficstars

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'

imkzh avatar May 17 '23 21:05 imkzh

Same situation for me! Found a solution by using sys.exit().

brinza888 avatar Nov 06 '23 22:11 brinza888

Run the code linter that is built into Pythonista. https://docs.astral.sh/ruff/rules/sys-exit-alias

cclauss avatar Nov 07 '23 00:11 cclauss

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?

brinza888 avatar Nov 07 '23 01:11 brinza888

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?

cclauss avatar Nov 07 '23 14:11 cclauss

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

imkzh avatar Nov 07 '23 14:11 imkzh

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!

brinza888 avatar Nov 08 '23 00:11 brinza888