If init flag is set, exit successfully immediately.
If not, only set the flag after successful initialization.
--- /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;