8000 bpo-46070: Fix asyncio initialisation guard (GH-30423) · python/cpython@9d18045 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d18045

Browse files
miss-islingtonErlend Egeberg Aasland
and
Erlend Egeberg Aasland
authored
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 <erlend.aasland@innova.no>
1 parent db60ed1 commit 9d18045

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
@@ -3309,17 +3309,14 @@ static int
33093309
module_init(void)
33103310
{
33113311
PyObject *module = NULL;
3312+
if (module_initialized) {
3313+
return 0;
3314+
}
33123315

33133316
asyncio_mod = PyImport_ImportModule("asyncio");
33143317
if (asyncio_mod == NULL) {
33153318
goto fail;
33163319
}
3317-
if (module_initialized != 0) {
3318-
return 0;
3319-
}
3320-
else {
3321-
module_initialized = 1;
3322-
}
33233320

33243321
current_tasks = PyDict_New();
33253322
if (current_tasks == NULL) {
@@ -3380,6 +3377,7 @@ module_init(void)
33803377
goto fail;
33813378
}
33823379

3380+
module_initialized = 1;
33833381
Py_DECREF(module);
33843382
return 0;
33853383

0 commit comments

Comments
 (0)
0