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.

Author vstinner
Recipients BTaskaya, arekm, gaborjbernat, miss-islington, pablogsal, vstinner
Date 2020-03-20.17:42:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584726166.79.0.532581067643.issue39360@roundup.psfhosted.org>
In-reply-to
Content
> Victor, are you OK if we backport both changes to 3.8?

Let me look at commit 9ad58acbe8b90b4d0f2d2e139e38bb5aa32b7fb6:
"bpo-19466: Py_Finalize() clears daemon threads earlier (GH-18848)"

Calling _PyThreadState_DeleteExcept() in Py_FinalizeEx() is really dangerous. It frees PyThreadState memory of daemon threads. Daemon threads continue to run while Py_FinalizeEx() is running (which takes an unknown amount of time, we only know that it's larger than 0 seconds). When a daemon thread attempts to acquire the GIL, it will likely crash if its PyThreadState memory is freed. This memory can be overriden by another memory allocation, or dereferencing the pointer can trigger a segmentation fault.

This change caused multiple regressions in the master branch. I had hard time to fix all crashes: I modified take_gil() 4 times, and I'm still not sure that my fix is correct. I had to modify take_gil() function which acquire the GIL: this function is really fragile and I would prefer to not touch it in a stable branch. See bpo-39877 changes to have an idea of the complexity of the problem.

Python finalization is really fragile: https://pythondev.readthedocs.io/finalization.html
History
Date User Action Args
2020-03-20 17:42:46vstinnersetrecipients: + vstinner, arekm, pablogsal, miss-islington, gaborjbernat, BTaskaya
2020-03-20 17:42:46vstinnersetmessageid: <1584726166.79.0.532581067643.issue39360@roundup.psfhosted.org>
2020-03-20 17:42:46vstinnerlinkissue39360 messages
2020-03-20 17:42:46vstinnercreate