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
Using logging or warnings during Python finalization does crash Python #86374
Comments
If you apply attached logging.patch, Python crash using attached crash.py: $ echo|./python -i crash.py
>>>
>>>
python: Python/_warnings.c:872: setup_context: Assertion `globals != NULL' failed.
Abandon (core dumped) Attached logging.patch is a fix for bpo-26789: logging.FileHandler keeps a reference to the builtin open() function. Attached crash.py does crash because of an unclosed file. It happens after PyInterpreterState_Clear(), in finalize_interp_clear():
setup_context() of Python/_warings.c does crash because tstate->interp->sysdict is NULL at this point. Moreover, _io.TextIOWrapper.__init__() fails to import the locale module (to call locale.getpreferredencoding(), since the encoding is None) and picks the "ascii" encoding. Moreover, even if I work around all these issues, _warnings.showwarnings() logs "lost sys.stderr" into stderr because, again, tstate->interp->sysdict is NULL at this point (and so sys.stderr no longer exists). It looks like a bug in finalize_interp_clear() which triggers a garbage collection, whereas Python is no longer usable. -- The logging module does automatically close files at exit using: atexit.register(shutdown) But crash.py, a new file is opened by a logging handler after logging.shutdown() is called. Maybe another problem is that the logging module does not clear logger handlers, or prevent handlers to log more message, after shutdown() is called. |
This change renames collect() to gc_collect_main(). It broke test_gdb on buildbots, whereas test_gdb passed on Travis CI on my PR 23038. Also, test_gdb is skipped on the Ubuntu job of GitHub Action since gdb is not installed. I created python/core-workflow#383 to add gdb to Ubuntu dependencies. My PR 23043 adds gdb dependency. |
Fixed by: commit 6e03c0a (upstream/master, master)
|
I fixed all issues which prevented to fix bpo-26789, I close thie issue. |
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: