import os
import signal
import sys
from multiprocessing import Process
class Watcher(object):
def __init__(self):
self.child = os.fork()
if self.child == 0:
return
else:
self.watch()
def watch(self):
try:
os.wait()
except KeyboardInterrupt:
self.kill()
sys.exit()
def kill(self):
try:
os.kill(self.child, signal.SIGKILL)
except OSError:
pass
def start_worker():
time.sleep(10)
if __name__ == '__main__':
Watcher()
process_list = []
for i in range(4):
process_list.append(Process(target=start_worker, args=()))
for p in process_list:
p.start()
for p in process_list:
p.join()