From b2ddf7979d228f2e61a4b9d174759ba39737930e Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Thu, 2 Dec 2010 04:11:46 +0000 Subject: Issue #9573: os.fork now works when triggered as a side effect of import (the wisdom of actually relying on this remains questionable!) --- Python/import.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Python') 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 -- cgit v1.2.1