[pypy-svn] r75375 - in pypy/trunk/pypy/tool: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Jun 13 16:11:13 CEST 2010
Author: arigo
Date: Sun Jun 13 16:11:12 2010
New Revision: 75375
Modified:
pypy/trunk/pypy/tool/runsubprocess.py
pypy/trunk/pypy/tool/test/test_runsubprocess.py
Log:
Test and fix for the case (caused I believe by forking) of a
subprocess that dies. In that case, re-create one and too bad
if this gives you an ENOMEM; this is supposed to be a rare
case seen during development.
Modified: pypy/trunk/pypy/tool/runsubprocess.py
==============================================================================
--- pypy/trunk/pypy/tool/runsubprocess.py (original)
+++ pypy/trunk/pypy/tool/runsubprocess.py Sun Jun 13 16:11:12 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/trunk/pypy/tool/test/test_runsubprocess.py
==============================================================================
--- pypy/trunk/pypy/tool/test/test_runsubprocess.py (original)
+++ pypy/trunk/pypy/tool/test/test_runsubprocess.py Sun Jun 13 16:11:12 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