➜

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
标题: [subinterpreters] atexit module should not be loaded more than once per interpreter
类型: Stage: resolved
Components: Subinterpreters Versions: Python 3.9
process
状态: closed Resolution: duplicate
Dependencies: 后续: Make atexit state per interpreter
View: 42639
分配给: 抄送列表: corona10, eric.snow, shihai1991, vstinner
优先级: normal 关键字: patch

Created on 2020-04-15 02:16 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19562 closed corona10, 2020-04-17 01:14
Messages (6)
msg366478 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2020-04-15 02:16
Since Python 3.7, it's possible to load the atexit module more than once:

commit 776407fe893fd42972c7e3f71423d9d86741d07c
Author: Marcel Plch <gmarcel.plch@gmail.com>
Date:   Wed Dec 20 11:17:58 2017 +0100

    bpo-31901: atexit callbacks should be run at subinterpreter shutdown (#4611)
    
    Change atexit behavior and PEP-489 multiphase init support.

Each new import executes the module which overrides PyInterpreterState.pyexitfunc with _Py_PyAtExit().

Example:
---
import sys

atexit1 = sys.modules.pop('atexit', None)
if atexit1 is None:
    import atexit as atexit1
    del sys.modules['atexit']

import atexit as atexit2

atexit1.register(print, "atexit1 callback")
atexit2.register(print, "atexit2 callback")
---

Output:
---
atexit2 callback
---

Either PyInterpreterState should support a list of exit functions, or atexit should raise an exception if it's loaded more than once.

call_ll_exitfuncs() calls a list of functions: _PyRuntimeState.exitfuncs. But these functions are called at the end of Py_Finalize(), whereas atexit functions are called after calling threading._shutdown() in Py_Finalize() and Py_EndInterpreter().
msg366517 - (view) Author: Dong-hee Na (corona10) * (Python committer) 日期: 2020-04-15 13:56
I will take a look :)
msg368666 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2020-05-11 22:12
I created bpo-40600: "Add an option to disallow creating more than one instance of a module".
msg376670 - (view) Author: Dong-hee Na (corona10) * (Python committer) 日期: 2020-09-10 03:22
@vstineer
I'd like to update PR 19562 not to create more than one instance.
if the PR is updated, would you like to review this PR?
msg376673 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2020-09-10 06:55
I would prefer a more generic solution, if possible:

> bpo-40600: "Add an option to disallow creating more than one instance of a module".
msg383878 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2020-12-27 23:43
Fixed by bpo-42639.
历史
日期 用户 动作 参数
2022-04-11 14:59:29admin修改github: 84468
2020-12-27 23:43:32vstinner修改状态: open -> closed
后续: Make atexit state per interpreter
消息: + msg383878

resolution: duplicate
stage: patch review -> resolved
2020-09-16 04:44:41shihai1991修改抄送: + shihai1991
2020-09-10 06:55:34vstinner修改消息: + msg376673
2020-09-10 03:22:36corona10修改消息: + msg376670
2020-05-15 00:43:26vstinner修改components: + Subinterpreters, - Library (Lib)
标题: atexit module should not be loaded more than once per interpreter -> [subinterpreters] atexit module should not be loaded more than once per interpreter
2020-05-11 22:12:52vstinner修改消息: + msg368666
2020-04-20 17:28:24corona10修改抄送: + eric.snow
2020-04-17 01:14:13corona10修改keywords: + patch
stage: patch review
pull_requests: + pull_request18906
2020-04-15 13:56:13corona10修改消息: + msg366517
2020-04-15 02:16:49vstinner创建