Closed daiguadaidai closed 6 years ago
Remove this line:
signal.signal(signal.SIGTERM, handle_interrupt)
Doing sys.exit(1)
in a signal handler does not work the way you expect.
@agronholm I want to kill parent process, and subprocess exit yet. what should do?
if use multiprocessing. I can
import multiprocessing
import time
import signal
import os
def func(msg):
for i in xrange(3):
print msg
time.sleep(1)
def term(sig_num, addtion):
print 'terminate process %d' % os.getpid()
try:
pool.terminate()
except Exception as e:
print str(e)
pool = multiprocessing.Pool(processes=4)
if __name__ == "__main__":
signal.signal(signal.SIGTERM, term)
for i in xrange(10):
msg = "hello %d" %(i)
pool.apply_async(func, (msg, ))
pool.close()
pool.join()
print "Sub-process(es) done."
I run program but can't kill parent proccess.
code:
run and press
Ctrl + C
can exit program:But use kill can't exit program
session1:run program:
session2:kill parent proccess:
what should i do?