From: Eric S. Raymond Date: Wed, 27 Nov 2013 00:45:58 +0000 (-0500) Subject: Required magic to kill the spawned instance. X-Git-Tag: 2.2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64dd476d6e921f549db27a22fd92f283313d46b6;p=irker.git Required magic to kill the spawned instance. --- diff --git a/irk b/irk index 49a083f..6307d65 100755 --- a/irk +++ b/irk @@ -16,6 +16,7 @@ import fileinput import subprocess import time import os +import signal import getopt def send(target, message): @@ -42,7 +43,7 @@ if __name__ == "__main__": except: # If it isn't, spawn an instance print "Spawning an irker instance..." - irkerd = subprocess.Popen("irkerd", shell=True) + irkerd = subprocess.Popen("irkerd", shell=True, preexec_fn=os.setsid) time.sleep(0.5) target = arguments[0] @@ -57,6 +58,7 @@ if __name__ == "__main__": send(target, message) if killafter: if irkerd: - irkerd.terminate() - irkerd.wait() + time.sleep(0.5) + # Magic required because shell=True, terminate() won't work. + os.killpg(irkerd.pid, signal.SIGTERM) print "...terminated."