From 778378590794559e6785728608140341c3928221 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 5 Jan 2022 20:27:20 +0100 Subject: [PATCH 1/2] bpo-46070: Fix asyncio initialisation guard If init flag is set, exit successfully immediately. If not, only set the flag after successful initialisation. --- Modules/_asynciomodule.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 978a1fdd0d8521..b08a7d1c024c37 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3318,17 +3318,14 @@ static int module_init(void) { PyObject *module = NULL; + if (module_initialized) { + return 0; + } asyncio_mod = PyImport_ImportModule("asyncio"); if (asyncio_mod == NULL) { goto fail; } - if (module_initialized != 0) { - return 0; - } - else { - module_initialized = 1; - } current_tasks = PyDict_New(); if (current_tasks == NULL) { @@ -3389,6 +3386,7 @@ module_init(void) goto fail; } + module_initialized = 1; Py_DECREF(module); return 0; From c47069da11f77b54122c34bd9fb45d24af3d381f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 7 Jan 2022 13:51:26 +0100 Subject: [PATCH 2/2] Add NEWS --- .../next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst diff --git a/Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst b/Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst new file mode 100644 index 00000000000000..0fedc9dfb8fb1b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-07-13-51-22.bpo-46070.-axLUW.rst @@ -0,0 +1,2 @@ +Fix possible segfault when importing the :mod:`asyncio` module from +different sub-interpreters in parallel. Patch by Erlend E. Aasland.