Skip to content

Commit b127e70

Browse files
author
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.
1 parent 994f90c commit b127e70

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
@@ -3318,17 +3318,14 @@ static int
33183318
module_init(void)
33193319
{
33203320
PyObject *module = NULL;
3321+
if (module_initialized) {
3322+
return 0;
3323+
}
33213324

33223325
asyncio_mod = PyImport_ImportModule("asyncio");
33233326
if (asyncio_mod == NULL) {
33243327
goto fail;
33253328
}
3326-
if (module_initialized != 0) {
3327-
return 0;
3328-
}
3329-
else {
3330-
module_initialized = 1;
3331-
}
33323329

33333330
current_tasks = PyDict_New();
33343331
if (current_tasks == NULL) {
@@ -3389,6 +3386,7 @@ module_init(void)
33893386
goto fail;
33903387
}
33913388

3389+
module_initialized = 1;
33923390
Py_DECREF(module);
33933391
return 0;
33943392

0 commit comments

Comments
 (0)