##// END OF EJS Templates
Add handler to terminate child process
Juan C. Espinoza -
r1533:37c6d1c7452d
parent child
Show More
@@ -14,7 +14,8 import datetime
14 import traceback
14 import traceback
15 import time
15 import time
16 import multiprocessing
16 import multiprocessing
17 from multiprocessing import Process, Queue
17 import signal as sig
18 from multiprocessing import Process, Queue, active_children
18 from threading import Thread
19 from threading import Thread
19 from xml.etree.ElementTree import ElementTree, Element, SubElement
20 from xml.etree.ElementTree import ElementTree, Element, SubElement
20
21
@@ -25,6 +26,15 from schainpy.utils import log
25 if 'darwin' in sys.platform and sys.version_info[0] == 3 and sys.version_info[1] > 7:
26 if 'darwin' in sys.platform and sys.version_info[0] == 3 and sys.version_info[1] > 7:
26 multiprocessing.set_start_method('fork')
27 multiprocessing.set_start_method('fork')
27
28
29 def handler(sig, frame):
30 # get all active child processes
31 active = active_children()
32 # terminate all active children
33 for child in active:
34 child.terminate()
35 # terminate the process
36 sys.exit(0)
37
28 class ConfBase():
38 class ConfBase():
29
39
30 def __init__(self):
40 def __init__(self):
@@ -659,6 +669,7 class Project(Process):
659 self.started = True
669 self.started = True
660 self.start_time = time.time()
670 self.start_time = time.time()
661 self.createObjects()
671 self.createObjects()
672 sig.signal(sig.SIGTERM, handler)
662 self.runProcs()
673 self.runProcs()
663 log.success('{} Done (Time: {:4.2f}s)'.format(
674 log.success('{} Done (Time: {:4.2f}s)'.format(
664 self.name,
675 self.name,
General Comments 0
You need to be logged in to leave comments. Login now