Required magic to kill the spawned instance.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 27 Nov 2013 00:45:58 +0000 (19:45 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 27 Nov 2013 00:45:58 +0000 (19:45 -0500)
irk

diff --git a/irk b/irk
index 49a083fb1b83c02be7a9c3234bc0d72168cf948f..6307d65cdc7a666961880aad69d61c1e4f1b4c87 100755 (executable)
--- a/irk
+++ b/irk
@@ -16,6 +16,7 @@ import fileinput
 import subprocess
 import time
 import os
 import subprocess
 import time
 import os
+import signal
 import getopt
 
 def send(target, message):
 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..."
     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]
         time.sleep(0.5)
 
     target = arguments[0]
@@ -57,6 +58,7 @@ if __name__ == "__main__":
         send(target, message)
     if killafter:
         if irkerd:
         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."
             print "...terminated."