[pypy-svn] r46394 - pypy/dist/pypy/translator/sandbox
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 7 13:49:08 CEST 2007
Author: arigo
Date: Fri Sep 7 13:49:07 2007
New Revision: 46394
Modified:
pypy/dist/pypy/translator/sandbox/pypy_interact.py
pypy/dist/pypy/translator/sandbox/sandlib.py
Log:
Double-check that the subprocess is killed when the controller ends.
Protects against the subprocess sending broken data causing an
exception in the controller, causing the timeout to be cancelled.
The subprocess would then be able to consume CPU cycles forever (without
any means of communication, though).
Modified: pypy/dist/pypy/translator/sandbox/pypy_interact.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/pypy_interact.py (original)
+++ pypy/dist/pypy/translator/sandbox/pypy_interact.py Fri Sep 7 13:49:07 2007
@@ -102,4 +102,7 @@
tmpdir=tmpdir)
if timeout is not None:
sandproc.settimeout(timeout, interrupt_main=True)
- sandproc.interact()
+ try:
+ sandproc.interact()
+ finally:
+ sandproc.kill()
Modified: pypy/dist/pypy/translator/sandbox/sandlib.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/sandlib.py (original)
+++ pypy/dist/pypy/translator/sandbox/sandlib.py Fri Sep 7 13:49:07 2007
@@ -11,6 +11,7 @@
from pypy.tool.ansi_print import AnsiLog
from pypy.rlib.rarithmetic import r_longlong
from py.compat import subprocess
+from pypy.tool.killsubprocess import killsubprocess
class MyAnsiLog(AnsiLog):
KW_TO_COLOR = {
@@ -132,7 +133,6 @@
amount of time. Only one timeout can be active at a time.
"""
import thread
- from pypy.tool.killsubprocess import killsubprocess
def _waiting_thread():
while True:
@@ -143,7 +143,7 @@
if delay <= 0.0:
break # expired!
time.sleep(min(delay*1.001, 1))
- self.withlock(killsubprocess, self.popen)
+ self.kill()
if interrupt_main:
if hasattr(os, 'kill'):
import signal
@@ -177,6 +177,9 @@
self.canceltimeout()
return returncode
+ def kill(self):
+ self.withlock(killsubprocess, self.popen)
+
def handle_forever(self):
returncode = self.handle_until_return()
if returncode != 0:
More information about the Pypy-commit
mailing list