|
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 |
| -importatexit |
12 |
| -importthread |
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 | +importatexit |
| 12 | +importthread |
| 13 | +atexit.register(thread.do_terminate_threads) |
| 14 | +
|
15 | 15 | def_init_signals():
|
16 |
| -"""Assure we shutdown our threads correctly when being interrupted""" |
17 |
| -importsignal |
18 |
| -importthread |
19 |
| -importsys |
20 |
| -
|
21 |
| -prev_handler=signal.getsignal(signal.SIGINT) |
22 |
| -defthread_interrupt_handler(signum,frame): |
23 |
| -thread.do_terminate_threads() |
24 |
| -ifcallable(prev_handler): |
25 |
| -prev_handler(signum,frame) |
26 |
| -raiseKeyboardInterrupt() |
27 |
| -# END call previous handler |
28 |
| -# END signal handler |
29 |
| -try: |
30 |
| -signal.signal(signal.SIGINT,thread_interrupt_handler) |
31 |
| -exceptValueError: |
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 | +importsignal |
| 18 | +importthread |
| 19 | +importsys |
| 20 | +
|
| 21 | +prev_handler=signal.getsignal(signal.SIGINT) |
| 22 | +defthread_interrupt_handler(signum,frame): |
| 23 | +thread.do_terminate_threads() |
| 24 | +ifcallable(prev_handler): |
| 25 | +prev_handler(signum,frame) |
| 26 | +raiseKeyboardInterrupt() |
| 27 | +# END call previous handler |
| 28 | +# END signal handler |
| 29 | +try: |
| 30 | +signal.signal(signal.SIGINT,thread_interrupt_handler) |
| 31 | +exceptValueError: |
| 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
|
|