changeset 19413:a4de0d3dc35a

run-tests: lock popen wait/poll In python2.4, any call to Popen() may attempt to wait on any active process, and wait is not thread-safe. Make it thread-safe. See http://bugs.python.org/issue1731717 for details.
author Brendan Cully <brendan@kublai.com>
date Wed, 17 Jul 2013 12:45:12 -0700
parents ea4342d0e6fe
children b927ccf0f27d
files tests/run-tests.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Tue Jul 16 17:10:26 2013 -0500
+++ b/tests/run-tests.py	Wed Jul 17 12:45:12 2013 -0700
@@ -59,6 +59,15 @@
 import Queue as queue
 
 processlock = threading.Lock()
+waitlock = threading.Lock()
+
+def waitlocked(fn):
+    def run():
+        waitlock.acquire()
+        ret = fn()
+        waitlock.release()
+        return ret
+    return run
 
 closefds = os.name == 'posix'
 def Popen4(cmd, wd, timeout, env=None):
@@ -67,6 +76,8 @@
                          close_fds=closefds,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT)
+    p.wait = waitlocked(p.wait)
+    p.poll = waitlocked(p.poll)
     processlock.release()
 
     p.fromchild = p.stdout
@@ -838,11 +849,7 @@
         cleanup()
         raise
 
-    try:
-        ret = proc.wait()
-    except OSError:
-        # Py2.4 seems to have a race here
-        pass
+    ret = proc.wait()
     if wifexited(ret):
         ret = os.WEXITSTATUS(ret)