diff options
Diffstat (limited to 'engine/SCons/Platform/win32.py')
-rw-r--r-- | engine/SCons/Platform/win32.py | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/engine/SCons/Platform/win32.py b/engine/SCons/Platform/win32.py index 2d6d970..3def1f8 100644 --- a/engine/SCons/Platform/win32.py +++ b/engine/SCons/Platform/win32.py @@ -8,7 +8,7 @@ selection method. """ # -# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation +# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -30,7 +30,7 @@ selection method. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Platform/win32.py issue-2856:2676:d23b7a2f45e8 2012/08/05 15:38:28 garyo" +__revision__ = "src/engine/SCons/Platform/win32.py 2013/03/03 09:48:35 garyo" import os import os.path @@ -81,8 +81,39 @@ else: builtins.file = _scons_file builtins.open = _scons_open - - +try: + import threading + spawn_lock = threading.Lock() + + # This locked version of spawnve works around a Windows + # MSVCRT bug, because its spawnve is not thread-safe. + # Without this, python can randomly crash while using -jN. + # See the python bug at http://bugs.python.org/issue6476 + # and SCons issue at + # http://scons.tigris.org/issues/show_bug.cgi?id=2449 + 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 +except ImportError: + # Use the unsafe method of spawnve. + # Please, don't try to optimize this try-except block + # away by assuming that the threading module is always present. + # In the test test/option-j.py we intentionally call SCons with + # a fake threading.py that raises an import exception right away, + # simulating a non-existent package. + def spawnve(mode, file, args, env): + return os.spawnve(mode, file, args, env) + # 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 # scons. @@ -123,7 +154,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): # 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: @@ -151,7 +182,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): 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]] |