summaryrefslogtreecommitdiff
blob: 23063cffd0c5f02cf5f47110f8ef792a99ddb2e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--- engine/SCons/compat/__init__.py (revision 2695)
+++ engine/SCons/compat/__init__.py (working copy)
@@ -167,11 +167,17 @@
     del shlex
     import_as('_scons_shlex', 'shlex')
 
-try:
-    import subprocess
-except ImportError:
-    # Pre-2.4 Python has no subprocess module.
-    import_as('_scons_subprocess', 'subprocess')
+#try:
+#    import subprocess
+#except ImportError:
+#    # Pre-2.4 Python has no subprocess module.
+#    import_as('_scons_subprocess', 'subprocess')
+
+# Import subprocess unconditionally to avoid possible race conditions in
+# the official subprocess API. If there are API versions without known
+# problems, we can version-check and use the original subprocess module
+# in these cases.
+import_as('_scons_subprocess', 'subprocess')
 
 import sys
 try:


--- engine/SCons/compat/_scons_subprocess.py (revision 2695)
+++ engine/SCons/compat/_scons_subprocess.py (working copy)
@@ -581,13 +581,19 @@
     class object:
         pass
 
+import thread
+lock = thread.allocate_lock()
+
 class Popen(object):
     def __init__(self, args, bufsize=0, executable=None,
                  stdin=None, stdout=None, stderr=None,
                  preexec_fn=None, close_fds=False, shell=False,
                  cwd=None, env=None, universal_newlines=False,
                  startupinfo=None, creationflags=0):
-        """Create new Popen instance."""
+        """Create new Popen instance.
+        Popen is not thread-safe and is therefore protected with a lock.
+        """
+        lock.acquire()
         _cleanup()
 
         self._child_created = False
@@ -655,6 +661,7 @@
                 self.stderr = os.fdopen(errread, 'rU', bufsize)
             else:
                 self.stderr = os.fdopen(errread, 'rb', bufsize)
+        lock.release()
 
 
     def _translate_newlines(self, data):