diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2010-12-02 04:11:46 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2010-12-02 04:11:46 (GMT) |
commit | b2ddf7979d228f2e61a4b9d174759ba39737930e (patch) | |
tree | 2df8dbbc25d0d3043b8c4843aa9dde91636373da /Python/import.c | |
parent | d2bb830edc7fc9e54b6ccd8c75a23ed8fee455e0 (diff) | |
download | cpython-b2ddf7979d228f2e61a4b9d174759ba39737930e.zip cpython-b2ddf7979d228f2e61a4b9d174759ba39737930e.tar.gz cpython-b2ddf7979d228f2e61a4b9d174759ba39737930e.tar.bz2 |
Issue #9573: os.fork now works when triggered as a side effect of import (the wisdom of actually relying on this remains questionable!)
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 67c4f70..e582a27 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 |