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: Better error handling in PyImport_Cleanup()
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, miss-islington, ncoghlan, pitrou, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-04-22 08:56 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 6564 merged serhiy.storchaka, 2018-04-22 09:06
PR 6601 merged miss-islington, 2018-04-25 17:59
PR 6604 merged serhiy.storchaka, 2018-04-25 18:46
PR 6605 merged serhiy.storchaka, 2018-04-25 18:47
PR 6606 merged serhiy.storchaka, 2018-04-25 18:52
PR 7068 closed vstinner, 2018-05-23 09:15
Messages (9)
msg315592 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-22 08:56
The proposed PR adds missed checks for errors and PyErr_Clear() calls in PyImport_Cleanup().

It may be worth to use PyErr_WriteUnraisable() in place of PyErr_Clear() (newly added and existing) in most cases. But this can add an unexpected noise, and I don't wont to do this at this stage of 3.7. It could be done in 3.8 though, and backported to 3.7 later.

I'm not sure that PyImport_Cleanup() works properly if sys.modules is not a dict. At this stage a custom mapping will likely be broken when most of modules are destroyed.
msg315751 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-25 17:58
New changeset e9d9494d6b2a5e0c2d48d22c7f0d5e95504b4f7e by Serhiy Storchaka in branch 'master':
bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564)
https://github.com/python/cpython/commit/e9d9494d6b2a5e0c2d48d22c7f0d5e95504b4f7e
msg315756 - (view) Author: miss-islington (miss-islington) Date: 2018-04-25 18:32
New changeset 291c9d4f74f3c7c57ae18e1aca617206795a090d by Miss Islington (bot) in branch '3.7':
bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564)
https://github.com/python/cpython/commit/291c9d4f74f3c7c57ae18e1aca617206795a090d
msg315757 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-25 18:56
PR 6606 replaces PyErr_Clear() with PyErr_WriteUnraisable(). This may add an unexpected noise at shutdown' but on other hand, this may be a helpful information in the case if something wrong happen. It doesn't produce additional output when run all tests, this means that that all is successful. I wonder in which circumstance that output will be occurred.
msg315766 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-26 00:27
New changeset b16681fb1e63f45361d1d68333d6dbdd4bf5435d by Serhiy Storchaka in branch '3.6':
[3.6] bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564). (GH-6604)
https://github.com/python/cpython/commit/b16681fb1e63f45361d1d68333d6dbdd4bf5435d
msg315767 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-26 00:28
New changeset 55299fffe328c3d2dfc222a22116b7e53bf2e962 by Serhiy Storchaka in branch '2.7':
[2.7] bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564). (GH-6605)
https://github.com/python/cpython/commit/55299fffe328c3d2dfc222a22116b7e53bf2e962
msg315915 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-29 19:16
New changeset c1a6832f50b36ffec299e6e6038535904e2b158d by Serhiy Storchaka in branch 'master':
bpo-33330: Write exceptions occurred in PyImport_Cleanup() to stderr. (GH-6606)
https://github.com/python/cpython/commit/c1a6832f50b36ffec299e6e6038535904e2b158d
msg317367 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-23 09:34
I reopen the issue because I created the PR 7068 to propose further checks (in debug mode).
msg317381 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-23 10:36
See also issue33379 about the bug in subinterpreters exposed when add yet one PyErr_WriteUnraisable() in PyImport_Cleanup() (it was not added because of this).
History
Date User Action Args
2022-04-11 14:58:59adminsetgithub: 77511
2018-05-23 10:36:34serhiy.storchakasetmessages: + msg317381
2018-05-23 09:34:43vstinnersetstatus: closed -> open
resolution: fixed ->
messages: + msg317367
2018-05-23 09:15:46vstinnersetpull_requests: + pull_request6696
2018-05-23 05:36:15serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-04-29 19:16:33serhiy.storchakasetmessages: + msg315915
2018-04-26 00:28:16serhiy.storchakasetmessages: + msg315767
2018-04-26 00:27:56serhiy.storchakasetmessages: + msg315766
2018-04-25 18:56:28serhiy.storchakasetmessages: + msg315757
2018-04-25 18:52:07serhiy.storchakasetpull_requests: + pull_request6302
2018-04-25 18:47:48serhiy.storchakasetpull_requests: + pull_request6301
2018-04-25 18:46:56serhiy.storchakasetpull_requests: + pull_request6300
2018-04-25 18:32:54miss-islingtonsetnosy: + miss-islington
messages: + msg315756
2018-04-25 17:59:50miss-islingtonsetpull_requests: + pull_request6296
2018-04-25 17:58:43serhiy.storchakasetmessages: + msg315751
2018-04-22 09:06:02serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request6259
2018-04-22 08:56:30serhiy.storchakacreate