Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Please scan-build.
[simgrid.git] / tools / tesh / tesh.py
index e389c25..37f8289 100755 (executable)
@@ -102,20 +102,20 @@ except NameError:
 #
 #
 
-DO_NOT_CLEAN_SUBPROCESSES = -1
-# Global variable. Stores which process group should be killed (or -1 if none)
-pgtokill = DO_NOT_CLEAN_SUBPROCESSES
+# Global variable. Stores which process group should be killed (or None otherwise)
+pgtokill = None
 
 def kill_process_group(pgid):
     # print("Kill process group {}".format(pgid))
     try:
         os.killpg(pgid, signal.SIGTERM)
-    except: # Ugly and psychorigid. Please improve python doc so we know what exceptions killpg can throw.
+    except OSError:
+        # os.killpg failed. OK. Some subprocesses may still be running.
         pass
 
 def signal_handler(signal, frame):
     print("Caught signal {}".format(SIGNALS_TO_NAMES_DICT[signal]))
-    if pgtokill != DO_NOT_CLEAN_SUBPROCESSES:
+    if pgtokill is not None:
         kill_process_group(pgtokill)
     tesh_exit(5)
 
@@ -317,8 +317,8 @@ class Cmd(object):
             proc = subprocess.Popen(args, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, preexec_fn=os.setsid)
             try:
                 pgtokill = os.getpgid(proc.pid)
-            except: # Ugly and psychorigid. Please improve python doc so we know what exceptions getpgid can throw.
-                # os.getpgid failed. OK, no cleanup.
+            except OSError:
+                # os.getpgid failed. OK. No cleanup.
                 pass
         except FileNotFoundError:
             print("["+FileReader().filename+":"+str(self.linenumber)+"] Cannot start '"+args[0]+"': File not found")
@@ -331,7 +331,7 @@ class Cmd(object):
         cmdName = FileReader().filename+":"+str(self.linenumber)
         try:
             (stdout_data, stderr_data) = proc.communicate("\n".join(self.input_pipe), self.timeout)
-            pgtokill = DO_NOT_CLEAN_SUBPROCESSES
+            pgtokill = None
         except subprocess.TimeoutExpired:
             print("Test suite `"+FileReader().filename+"': NOK (<"+cmdName+"> timeout after "+str(self.timeout)+" sec)")
             kill_process_group(pgtokill)