diff options
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c index 67c4f70adb..e582a277d4 100644 --- a/Python/import.c +++ b/Python/import.c @@ -325,8 +325,17 @@ _PyImport_ReInitLock(void) { if (import_lock != NULL) import_lock = PyThread_allocate_lock(); - import_lock_thread = -1; - import_lock_level = 0; + if (import_lock_level > 1) { + /* Forked as a side effect of import */ + long me = PyThread_get_thread_ident(); + PyThread_acquire_lock(import_lock, 0); + /* XXX: can the previous line fail? */ + import_lock_thread = me; + import_lock_level--; + } else { + import_lock_thread = -1; + import_lock_level = 0; + } } #endif |