Skip to content

Commit 4d2cfd3

Browse files
miss-islingtonErlend Egeberg Aasland
andauthored
bpo-46070: Fix asyncio initialisation guard (GH-30423)
If init flag is set, exit successfully immediately. If not, only set the flag after successful initialization. (cherry picked from commit b127e70) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent 188fbde commit 4d2cfd3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible segfault when importing the :mod:`asyncio` module from
2+
different sub-interpreters in parallel. Patch by Erlend E. Aasland.

Modules/_asynciomodule.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,17 +3328,14 @@ static int
33283328
module_init(void)
33293329
{
33303330
PyObject *module = NULL;
3331+
if (module_initialized) {
3332+
return 0;
3333+
}
33313334

33323335
asyncio_mod = PyImport_ImportModule("asyncio");
33333336
if (asyncio_mod == NULL) {
33343337
goto fail;
33353338
}
3336-
if (module_initialized != 0) {
3337-
return 0;
3338-
}
3339-
else {
3340-
module_initialized = 1;
3341-
}
33423339

33433340
current_tasks = PyDict_New();
33443341
if (current_tasks == NULL) {
@@ -3399,6 +3396,7 @@ module_init(void)
33993396
goto fail;
34003397
}
34013398

3399+
module_initialized = 1;
34023400
Py_DECREF(module);
34033401
return 0;
34043402

0 commit comments

Comments
 (0)