diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2015-10-10 15:10:10 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-10-10 15:10:10 -0400 |
commit | 438ed1265ea9b4b7957d4b3b098abab6a37ebb5a (patch) | |
tree | 1f46aaa216aa7bafa0f5dfc0e4c50ef15eb0a26a /grs/Execute.py | |
parent | grs/Interpret.py: fix minor errors. (diff) | |
download | grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.tar.gz grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.tar.bz2 grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.zip |
grs/Execute.py, Interpret.py: clean up signal code
While the following may look like a good idea, its not:
while True:
os.kill(pid, signal.SIGKILL)
If pid is zombied, we're stuck in an infinite loop. Rather
for all processes in the cgroup we just aggressively send a
SIGKILL until only the first ancestor remains.
Diffstat (limited to 'grs/Execute.py')
-rw-r--r-- | grs/Execute.py | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/grs/Execute.py b/grs/Execute.py index 0e70221..7b0e5a2 100644 --- a/grs/Execute.py +++ b/grs/Execute.py @@ -42,12 +42,6 @@ class Execute(): logfile - A file to log output to. If logfile = None, then we log to sys.stdout. """ - def signalexit(): - pid = os.getpid() - while True: - os.kill(pid, signal.SIGTERM) - time.sleep(2.0) - if shell: args = cmd else: @@ -71,19 +65,16 @@ class Execute(): if not timed_out: # _rc = None if we had a timeout _rc = proc.returncode - if _rc: - _file.write('EXIT CODE: %d\n' % _rc) - if not failok: - _file.write('SENDING SIGTERM\n') - _file.close() - signalexit() + _file.write('EXIT CODE: %d\n' % _rc) if timed_out: _file.write('TIMEOUT ERROR: %s\n' % cmd) - if not failok: - _file.write('SENDING SIGTERM\n') - _file.close() - signalexit() + + if not failok and ( _rc != 0 or timed_out): + pid = os.getpid() + _file.write('SENDING SIGTERM: %s\n' % pid) + _file.close() + os.kill(pid, signal.SIGTERM) # Only close a logfile, don't close sys.stderr! if logfile: |