New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Py_Main() does not return on SystemExit #50747
Comments
From teh docs: http://docs.python.org/c-api/veryhigh.html int Py_Main(int argc, char **argv)¶
available for programs which embed Python. The argc and argv parameters
function will not return 1, but exit the process, as long as Py_Main() still does not return on SystemExit. |
I'm having the same problem. The source of the problem seem to be in |
As a workaround, I copied teh function PyRun_InteractiveOneFlags() to my |
bump |
bump =op |
Can you propose a patch fixing this issue? |
I will try to fix and submit a patch. Just a second =op |
Isn't the only problem here that the docs refer to SystemError instead of SystemExit - eg 'raise SystemError("foo")' in an interactive session doesn't terminate the process at all (and I don't believe it should) whereas SystemExit obviously does. |
Wat did you say? I tried to fix this issue at teh time with no success. It would require too |
Note the quoted documentation in comment 1, the paragraph "Note that if an otherwise unhandled SystemError ..." I don't think that paragraph is correct - SystemError doesn't seem to terminate Py_Main - but if you replace "SystemError" with "SystemExit", that paragraph is correct, including the comment about Py_InspectFlag. So I think there are 2 simple documentation bugs (the component of this bug is "Documentation") and not necessarily a behaviour bug (even though the "type" is set to behaviour :)
I just traced through this in Python 2.6 - PyRun_InteractiveOneFlags winds up calling PyErr_PrintEx() and this function explicitly checks for SystemExit and calls handle_system_exit, which calls exit(). There doesn't seem to be any special handling for SystemError at all. |
So there is a disconnect. You can either change the documentation to match the behavior or you can change the code to match the documentation. I would prefer to leave the documentation alone and make Py_Main return rather than exit on sys.exit. That's just my 2 cents. |
Sorry, some years have passed since I posted this. I will take a look on teh |
I reviewed teh problem and rewrote teh text to better explain what is *** From teh docs: http://docs.python.org/c-api/veryhigh.html int Py_Main(int argc, char **argv)¶
available for programs which embed Python. The argc and argv parameters
function will not return 1, but exit the process, as long as *** Teh problem:
exception. If a unhandled exception is caught, teh function prints teh ...
>>> raise(SystemError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError
>>> Consequently, Py_Main() does not return on unhandled SystemExit. But not ...
Py_Main(argc, argv);
fprintf(stderr, "reached!");
... ...
>>> raise(SystemExit)
$ note it did not print after Py_Main() termination. *** Analysis:
triggered in function PyErr_PrintEx(). For some reason, SystemExit is
this could be accomplished with some set/longjmp, but still some *** Possible solutions:
*** Proposed solution:
had Py_Main() running on a thread. If teh user typed exit() in Python,
exception. This should be done by a function liek
exception handling should only occur after giving teh programmer a
except, maybe, in some function which is a explicit wrapper.
have, for now, a warning at teh docs for every bad behaving function, |
@rogi - you seem to have a problem with your keyboard - the 'h' and 'e' keys seem to have been swapped. The docs are wrong regardless - I don't think anyone would suggest the behaviour match the docs regarding SystemError - having Py_Main return on SystemError would be backwards incompatible. Given the discussion in those docs about SystemError, I'm confident that the person who wrote the docs was simply attempting to document the actual implementation and made an error. The implementation has, as far as I know, always worked the way it does (ie, there has never been a regression in this). So IMO there are 2 issues:
|
those functions terminate your process as they wish. Teh programmer
blender crash when I typed raise(SystemExit) on its interactive console.
hacked to maintain it and achieve teh desired behaviour during
...
#define GOOD_BEHAVING_PYTHON 1
#include <Python.h>
...
PyRun_SimpleString(...);
/* if he wants to, he can do teh following */
PyErr_Print();
PyErr_Handle();
... this way, Py_Main() could be implemented in a way it would return to its
Cheers. |
SystemError and not SystemExit. In fact, Py_Main() should not return on
messages or call exit() as they wish. They should be split so teh
backward compatibility. Cheers. |
@rogi - you might like to re-read my responses a couple more times:
|
You said:
but teh problem is:
and documentation says:
which seems to be teh desired and broken behaviour. Similar problems happen with other functions, such as Also, I am not asking for a new feature. I'm pointing that there is I hope this clarified teh situation. |
Correct - the docs should be fixed - which is what this bug is currently addressing (see the "Components" and "Assigned To" fields)
Nope - it is the docs. The docs were written after the code and incorrectly describe it in 2 important ways. If you want the code to change the way it has been forever, then you are asking for a new feature. |
Fair. Still I dont liek it very much. I will return! |
For completeness, here is a doc patch against 2.6 which corrects the documentation. |
I may be wrong, but I think Py_Main() will _never_ return 1. |
Oh, and other functions on this doc, such as PyRun_SimpleStringFlags(), |
It will return 1 if you specify a script to run and that has an unhandled exception. |
Good catch - new patch with PyRun_SimpleStringFlags() corrected too. |
The SystemExit vs. SystemError is clearly a typo in the doc. The VC comment accompanying the addition of that note says "note that Py_Main doesnt return on SystemExit." See [e5d8f0c0d634] and bpo-5227. |
The updated doc patch is missing :exc: markup on one of "SystemExit"s. |
The comment in the source that describes |
New changeset 0311f62714f7 by Georg Brandl in branch '3.1': New changeset 7089afd69a1a by Georg Brandl in branch '3.2': New changeset 94e3c44b0662 by Georg Brandl in branch 'default': New changeset 97a75fccd7c8 by Georg Brandl in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: