This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Rework Python finalization
Type: Stage:
Components: Versions: Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, vstinner
Priority: normal Keywords:

Created on 2014-06-17 07:40 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_4_daemon_threads.py vstinner, 2014-06-17 07:40
Messages (4)
msg220804 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-06-17 07:40
Hi,

During the development of Python 3.4, I tried to emit warnings if a file is destroyed without being explicitly closed. The warnings were not emited in threads during Python finalization. Here are related changes:

- Issue #19421: "FileIO destructor imports indirectly the io module at exit"
- Issue #19424: "_warnings: patch to avoid conversions from/to UTF-8"
- Issue #19442: "Python crashes when a warning is emitted during shutdown"
- Change in Python shutdown: issue #19466 "Clear state of threads earlier in Python shutdown"
- Regression => issue #20526

The change #19466 had to be reverted a few days before the release of Python 3.4.0 because it caused the regression #20526.

I'm still not convinced that #20526 was a new bug. IMO the bug still exists, but it is just less likely without the change #19466.

There is still something wrong in Python finalization, so I open this issue to rework it.

The goal is to get warnings in test_4_daemon_threads() of test_threading. I attached the test as a Python script.
msg220805 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-06-17 07:41
Benjamin changed ThreadState_DeleteCurrent() to fix an issue in this part of the code, but then reverted his change:
"revert tstate_delete_common, since it's pretty much wrong"
http://hg.python.org/cpython/rev/3ce746735b99

(Yeah this part of the code is really tricky, likely to deadlock.)
msg220807 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-06-17 07:57
Charles-François Natali wrote a general comment about daemon threads:
http://bugs.python.org/issue19466#msg206028
msg238436 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-18 13:30
This issue was more a reminder for myself (TODO). I'm no more interesting to work on it, so I close it.

The Python finalization is very fragile. I prefer to not touch it again :-p
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 65987
2015-03-18 13:30:34vstinnersetstatus: open -> closed
resolution: out of date
messages: + msg238436
2014-06-17 07:57:50vstinnersetmessages: + msg220807
2014-06-17 07:41:46vstinnersetmessages: + msg220805
2014-06-17 07:40:27vstinnercreate