[pypy-svn] r38450 - pypy/dist/pypy/tool

pedronis at codespeak.net pedronis at codespeak.net
Sun Feb 11 12:48:24 CET 2007


Author: pedronis
Date: Sun Feb 11 12:48:23 2007
New Revision: 38450

Modified:
   pypy/dist/pypy/tool/watchdog.py
Log:
if the watched process died with a signal, print the signal name and consider this a variation on "timeout"



Modified: pypy/dist/pypy/tool/watchdog.py
==============================================================================
--- pypy/dist/pypy/tool/watchdog.py	(original)
+++ pypy/dist/pypy/tool/watchdog.py	Sun Feb 11 12:48:23 2007
@@ -1,9 +1,18 @@
 import sys, os, signal
 import threading
 
+def getsignalname(n):
+    for name, value in signal.__dict__.items():
+        if value == n and name.startswith('SIG'):
+            return name
+    return 'signal %d' % (n,)
+
 timeout = float(sys.argv[1])
+timedout = False
 
 def childkill():
+    global timedout
+    timedout = True
     sys.stderr.write("="*26 + "timedout" + "="*26 + "\n")
     try:
         os.kill(pid, signal.SIGTERM)
@@ -27,6 +36,13 @@
     if os.WIFEXITED(status):
         sys.exit(os.WEXITSTATUS(status))
     else:
+        assert os.WIFSIGNALED(status)
+        sign = os.WTERMSIG(status)
+        if timedout and sign == signal.SIGTERM:
+            sys.exit(1)
+        signame = getsignalname(sign)
+        sys.stderr.write("="*26 + "timedout" + "="*26 + "\n")        
+        sys.stderr.write("="*25 + " %-08s " %  signame + "="*25 + "\n")
         sys.exit(1)
 
     



More information about the Pypy-commit mailing list