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: Raising in an atexit function in dev mode crashes
Type: Stage: resolved
Components: Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pablogsal, vstinner
Priority: normal Keywords: 3.10regression, 3.11regression, patch

Created on 2021-12-09 11:20 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30002 merged pablogsal, 2021-12-09 11:42
PR 30005 merged miss-islington, 2021-12-09 13:53
Messages (6)
msg408106 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-09 11:20
Issue found by Matt Wozniski:

Running this with python3.10 -X dev segfaults:

import atexit
def func():
    atexit.unregister(func)
    1/0
atexit.register(func)
msg408123 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-09 13:53
New changeset f0d290d25cad66e615ada68ba190b8a23ac1deaa by Pablo Galindo Salgado in branch 'main':
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002)
https://github.com/python/cpython/commit/f0d290d25cad66e615ada68ba190b8a23ac1deaa
msg408132 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-09 15:16
New changeset 934a24c641da5bc4bdb724e901adc20f9a5dff40 by Miss Islington (bot) in branch '3.10':
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002) (GH-30005)
https://github.com/python/cpython/commit/934a24c641da5bc4bdb724e901adc20f9a5dff40
msg408143 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-12-09 17:01
Interesting bug report! Thanks for the fix ;-)
msg408144 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-12-09 17:03
For me, the question is why would anyone call atexit.unregister() inside an atexit callback. Is it useful?

atexit._run_exitfuncs() removes all registered callbacks.

Py_Finalize() calls _PyAtExit_Call() which also removes all registered callbacks.
msg408147 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-09 17:06
>For me, the question is why would anyone call atexit.unregister() inside an atexit callback. Is it useful?

Is not useful, is just an edge case
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90183
2021-12-09 17:06:29pablogsalsetmessages: + msg408147
2021-12-09 17:03:09vstinnersetmessages: + msg408144
2021-12-09 17:01:17vstinnersetmessages: + msg408143
2021-12-09 15:16:19pablogsalsetmessages: + msg408132
2021-12-09 15:15:34pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-12-09 13:53:57miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28229
2021-12-09 13:53:54pablogsalsetmessages: + msg408123
2021-12-09 11:42:59pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28226
2021-12-09 11:23:27pablogsalsetnosy: + vstinner
2021-12-09 11:20:52pablogsalcreate