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
Python crashes when a warning is emitted during shutdown #63641
Comments
Because of a bug, warnings were not emitted during Python shutdown. I fixed the bug in issue bpo-19424, and now Python crashs when a warning is emitted during shutdown. See also issue bpo-19421: "FileIO destructor imports indirectly the io module at exit". The warnings module uses globals()['__name__'] to get the name of the current module. The bug was the during Python shutdown, the module is None and _PyUnicode_AsString(None) was raising an exception (in setup_context() of _warnings.c) and so the warning was not emitted. For example, FileIO destructor emits a warning when a unclosed file is destroyed. The destructor removes the exception raised the warning module. |
New changeset 1787277915e9 by Victor Stinner in branch 'default': |
The changeset 1787277915e9 is closer to a workaround than a real fix: + if (module != Py_None) { |
warn_shutdown.py: example of script emitting warning at shutdown. Depending on the timing, the warning is shown or not (replace "if 0:" with "if 1:" to always display the warning). This example is a simplified example of the original crasher: test_threading.test_4_daemon_threads(). |
warn_shutdown.py does not emit warnings because the thread states are destroyed too late, when the modules have been destroyed. I opened a new issue bpo-19466 "Clear state of threads earlier in Python shutdown" which would permit to emit properly warnings, at least for the specific case of warn_shutdown.py.
If the module is None, it's too late: modules have been destroyed, so it's safer to not call warn_explicit() and do nothing. I tested to fail with an assertion error if a warning is emitted too late (ie. when module is None). test_threading.test_4_daemon_threads() does fail in this case. Using the patch attached to bpo-19466, the full test suite pass correctly. |
New changeset 13a05ed33cf7 by Victor Stinner in branch 'default': |
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: