[pypy-svn] r75376 - in pypy/branch/multijit-4/pypy/tool: . test

arigo at codespeak.net arigo at codespeak.net
Sun Jun 13 16:12:08 CEST 2010


Author: arigo
Date: Sun Jun 13 16:12:07 2010
New Revision: 75376

Modified:
   pypy/branch/multijit-4/pypy/tool/runsubprocess.py
   pypy/branch/multijit-4/pypy/tool/test/test_runsubprocess.py
Log:
Merge r75375 from trunk.


Modified: pypy/branch/multijit-4/pypy/tool/runsubprocess.py
==============================================================================
--- pypy/branch/multijit-4/pypy/tool/runsubprocess.py	(original)
+++ pypy/branch/multijit-4/pypy/tool/runsubprocess.py	Sun Jun 13 16:12:07 2010
@@ -5,7 +5,6 @@
 
 import sys
 import os
-import warnings
 from subprocess import PIPE, Popen
 
 def run_subprocess(executable, args, env=None, cwd=None):
@@ -46,16 +45,21 @@
     # do this at import-time, when the process is still tiny
     _source = os.path.dirname(os.path.abspath(__file__))
     _source = os.path.join(_source, 'runsubprocess.py')   # and not e.g. '.pyc'
-    # Let's not hear about os.popen2's deprecation.
-    warnings.filterwarnings("ignore", ".*popen2.*", DeprecationWarning,
-                            "pypy.tool.runsubprocess")
-    _child_stdin, _child_stdout = os.popen2(
-        "'%s' '%s'" % (sys.executable, _source))
+
+    def spawn_subprocess():
+        global _child
+        _child = Popen([sys.executable, _source], bufsize=0,
+                       stdin=PIPE, stdout=PIPE, close_fds=True)
+    spawn_subprocess()
 
     def _run(*args):
-        _child_stdin.write('%r\n' % (args,))
-        _child_stdin.flush()
-        results = _child_stdout.readline()
+        try:
+            _child.stdin.write('%r\n' % (args,))
+        except (OSError, IOError):
+            # lost the child.  Try again...
+            spawn_subprocess()
+            _child.stdin.write('%r\n' % (args,))
+        results = _child.stdout.readline()
         assert results.startswith('(')
         results = eval(results)
         if results[0] is None:

Modified: pypy/branch/multijit-4/pypy/tool/test/test_runsubprocess.py
==============================================================================
--- pypy/branch/multijit-4/pypy/tool/test/test_runsubprocess.py	(original)
+++ pypy/branch/multijit-4/pypy/tool/test/test_runsubprocess.py	Sun Jun 13 16:12:07 2010
@@ -30,3 +30,12 @@
     assert returncode == 1
     assert stdout == ''
     assert 'no/such/filename' in stderr
+
+def test_recover_lost_process():
+    if not hasattr(os, 'fork'):
+        py.test.skip("there is no os.fork()")
+    from pypy.tool import runsubprocess
+    import signal
+    os.kill(runsubprocess._child.pid, signal.SIGTERM)
+    runsubprocess._child.wait()
+    test_echo()



More information about the Pypy-commit mailing list