blob: e212f1b21de241b8ab6623dffbe272ab7a534d72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
"""Initialize the multi-processing package"""
#{ Initialization
def _init_atexit():
"""Setup an at-exit job to be sure our workers are shutdown correctly before
the interpreter quits"""
import atexit
import thread
atexit.register(thread.do_terminate_threads)
def _init_signals():
"""Assure we shutdown our threads correctly when being interrupted"""
import signal
import thread
prev_handler = signal.getsignal(signal.SIGINT)
def thread_interrupt_handler(signum, frame):
thread.do_terminate_threads()
if callable(prev_handler):
prev_handler(signum, frame)
raise KeyboardInterrupt()
# END call previous handler
# END signal handler
signal.signal(signal.SIGINT, thread_interrupt_handler)
#} END init
_init_atexit()
_init_signals()
|