Skip to contentSkip to conversation

Kill suprocesses when pressing ctrl+c

PATCH In review Marius Avram 1 participant 1 message Aug 22, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v3 2/2 Kill suprocesses when pressing ctrl+c

This way the created bitbake subprocesses from the upgrade script are killed as well when you press ctrl+c.

---
 upgradehelper.py |    6 ++++++
 1 file changed, 6 insertions(+)
upgradehelper.py +6 -0
index 658ec43..6be7ac2 100755
@@ -35,6 +35,7 @@ from logging import warning as W
 from logging import error as E
 from logging import critical as C
 import re
+import signal
 import sys
 import ConfigParser as cp
 from datetime import datetime
@@ -648,11 +649,16 @@ class UniverseUpdater(Updater):
         self.prepare()
         super(UniverseUpdater, self).run()
 
+def close_child_processes(signal_id, frame):
+    pid = os.getpgrp()
+    os.killpg(pid, signal.SIGKILL)
 
 if __name__ == "__main__":
     global settings
     global maintainer_override
 
+    signal.signal(signal.SIGINT, close_child_processes)
+
     debug_levels = [log.CRITICAL, log.ERROR, log.WARNING, log.INFO, log.DEBUG]
     args = parse_cmdline()
     log.basicConfig(format='%(levelname)s:%(message)s',
Signature · 1 line
1.7.9.5