If init flag is set, exit successfully immediately.
If not, only set the flag after successful initialization.
(cherry picked from commit
b127e70a8a682fe869c22ce04c379bd85a00db67)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
--- /dev/null
+Fix possible segfault when importing the :mod:`asyncio` module from
+different sub-interpreters in parallel. Patch by Erlend E. Aasland.
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) {
goto fail;
}
+ module_initialized = 1;
Py_DECREF(module);
return 0;