|
6 | 6 |
|
7 | 7 | #{ Initialization |
8 | 8 | def _init_atexit(): |
9 | | - """Setup an at-exit job to be sure our workers are shutdown correctly before |
10 | | - the interpreter quits""" |
11 | | - import atexit |
12 | | - import thread |
13 | | - atexit.register(thread.do_terminate_threads) |
14 | | - |
| 9 | + """Setup an at-exit job to be sure our workers are shutdown correctly before |
| 10 | + the interpreter quits""" |
| 11 | + import atexit |
| 12 | + import thread |
| 13 | + atexit.register(thread.do_terminate_threads) |
| 14 | + |
15 | 15 | def _init_signals(): |
16 | | - """Assure we shutdown our threads correctly when being interrupted""" |
17 | | - import signal |
18 | | - import thread |
19 | | - import sys |
20 | | - |
21 | | - prev_handler = signal.getsignal(signal.SIGINT) |
22 | | - def thread_interrupt_handler(signum, frame): |
23 | | - thread.do_terminate_threads() |
24 | | - if callable(prev_handler): |
25 | | - prev_handler(signum, frame) |
26 | | - raise KeyboardInterrupt() |
27 | | - # END call previous handler |
28 | | - # END signal handler |
29 | | - try: |
30 | | - signal.signal(signal.SIGINT, thread_interrupt_handler) |
31 | | - except ValueError: |
32 | | - # happens if we don't try it from the main thread |
33 | | - print >> sys.stderr, "Failed to setup thread-interrupt handler. This is usually not critical" |
34 | | - # END exception handling |
| 16 | + """Assure we shutdown our threads correctly when being interrupted""" |
| 17 | + import signal |
| 18 | + import thread |
| 19 | + import sys |
| 20 | + |
| 21 | + prev_handler = signal.getsignal(signal.SIGINT) |
| 22 | + def thread_interrupt_handler(signum, frame): |
| 23 | + thread.do_terminate_threads() |
| 24 | + if callable(prev_handler): |
| 25 | + prev_handler(signum, frame) |
| 26 | + raise KeyboardInterrupt() |
| 27 | + # END call previous handler |
| 28 | + # END signal handler |
| 29 | + try: |
| 30 | + signal.signal(signal.SIGINT, thread_interrupt_handler) |
| 31 | + except ValueError: |
| 32 | + # happens if we don't try it from the main thread |
| 33 | + print >> sys.stderr, "Failed to setup thread-interrupt handler. This is usually not critical" |
| 34 | + # END exception handling |
35 | 35 |
|
36 | 36 |
|
37 | 37 | #} END init |
|
0 commit comments