scons: Monkey patch os.spawnve on Windows to become thread safe.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 14 Jul 2009 10:09:23 +0000 (11:09 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 14 Jul 2009 11:21:25 +0000 (12:21 +0100)
See also:
- http://bugs.python.org/issue6476
- http://scons.tigris.org/issues/show_bug.cgi?id=2449

scons/fixes.py [new file with mode: 0644]
scons/gallium.py

diff --git a/scons/fixes.py b/scons/fixes.py
new file mode 100644 (file)
index 0000000..714cccf
--- /dev/null
@@ -0,0 +1,27 @@
+import sys
+
+# Monkey patch os.spawnve on windows to become thread safe
+if sys.platform == 'win32':
+    import os
+    import threading
+    from os import spawnve as old_spawnve
+
+    spawn_lock = threading.Lock()
+
+    def new_spawnve(mode, file, args, env):
+        spawn_lock.acquire()
+        try:
+            if mode == os.P_WAIT:
+                ret = old_spawnve(os.P_NOWAIT, file, args, env)
+            else:
+                ret = old_spawnve(mode, file, args, env)
+        finally:
+            spawn_lock.release()
+        if mode == os.P_WAIT:
+            pid, status = os.waitpid(ret, 0)
+            ret = status >> 8
+        return ret
+
+    os.spawnve = new_spawnve
+
+
index 217478bd50df467d50903e0c0cb1315dd4ad76b4..8082aba6f2f6e32db8fcb32bb49a85ec6863c7e7 100644 (file)
@@ -38,6 +38,8 @@ import SCons.Action
 import SCons.Builder
 import SCons.Scanner
 
+import fixes
+
 
 def quietCommandLines(env):
     # Quiet command lines