Gary Oberbrunner avatar Gary Oberbrunner committed 8f06e41 Merge

Merge pull request #34, fix spawn on Windows, from Evgeny Podjachev.

Comments (0)

Files changed (2)

 
 RELEASE 2.X.X - 
 
+  From Thomas Berg and Evgeny Podjachev:
+    - Fix subprocess spawning on Windows.  Work around a Windows
+      bug that can crash python occasionally when using -jN. (#2449)
+
   From Dirk Baechle:
     - Updated test framework to support dir and file fixtures and
       added ability to test external (out-of-tree) tools.

src/engine/SCons/Platform/win32.py

 import os.path
 import sys
 import tempfile
+import threading
 
 from SCons.Platform.posix import exitvalmap
 from SCons.Platform import TempFileMunge
     builtins.file = _scons_file
     builtins.open = _scons_open
 
+spawn_lock = threading.Lock()
 
+def spawnve(mode, file, args, env):
+    spawn_lock.acquire()
+    try:
+        if mode == os.P_WAIT:
+            ret = os.spawnve(os.P_NOWAIT, file, args, env)
+        else:
+            ret = os.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
 
 # The upshot of all this is that, if you are using Python 1.5.2,
 # you had better have cmd or command.com in your PATH when you run
         # actually do the spawn
         try:
             args = [sh, '/C', escape(' '.join(args)) ]
-            ret = os.spawnve(os.P_WAIT, sh, args, env)
+            ret = spawnve(os.P_WAIT, sh, args, env)
         except OSError, e:
             # catch any error
             try:
 
 def exec_spawn(l, env):
     try:
-        result = os.spawnve(os.P_WAIT, l[0], l, env)
+        result = spawnve(os.P_WAIT, l[0], l, env)
     except OSError, e:
         try:
             result = exitvalmap[e[0]]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.