Skip to content

Commit 281d43b

Browse files
committed
Better handle cases where the subprocess actually dies fine
1 parent 42ecdca commit 281d43b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/watch.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,29 @@ def launchAndSendSignal(command, sig, timeout):
5757
ae.join()
5858
return rc
5959
if timeout > 0 and (time.clock() - start) > timeout:
60-
print ('Timeout reached: sending %s signal to process %s' %(sig, proc.pid))
6160
# Here it is *fundamental* to use killpg to reach all the processes
6261
# in the process group. This covers cases where for example root is invoked
6362
# and it launches root.exe -splash
64-
pgid = os.getpgid(proc.pid)
63+
try:
64+
pgid = os.getpgid(proc.pid)
65+
except:
66+
pgid = 0
67+
if 0 == pgid:
68+
rc = ae.Poll()
69+
ae.join()
70+
return rc
71+
print ('Timeout reached: sending %s signal to process %s' %(sig, proc.pid))
6572
os.killpg(pgid, sig)
6673
# give the time to GDB to fire up
6774
time.sleep(timeoutOffset)
6875
# here we tap again on the process group to allow the printing on screen of the
6976
# full stack trace built with gdb. This is a bit of black magic.
7077
# It is not yet clear why to flush the buffers the process group needs
7178
# to be terminated by hand and it does not terminate by itself.
72-
os.killpg(pgid, signal.SIGKILL)
79+
try:
80+
os.killpg(pgid, signal.SIGKILL)
81+
except:
82+
pass
7383
ae.join()
7484
return 1
7585

0 commit comments

Comments
 (0)