Skip to content
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit 5992bb6

Browse files
committed
async.init: signal initialization failure is now cought, and a warning message is printed to inform about it
1 parent e527a5d commit 5992bb6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def _init_signals():
1212
"""Assure we shutdown our threads correctly when being interrupted"""
1313
import signal
1414
import thread
15+
import sys
1516

1617
prev_handler = signal.getsignal(signal.SIGINT)
1718
def thread_interrupt_handler(signum, frame):
@@ -21,7 +22,12 @@ def thread_interrupt_handler(signum, frame):
2122
raise KeyboardInterrupt()
2223
# END call previous handler
2324
# END signal handler
24-
signal.signal(signal.SIGINT, thread_interrupt_handler)
25+
try:
26+
signal.signal(signal.SIGINT, thread_interrupt_handler)
27+
except ValueError:
28+
# happens if we don't try it from the main thread
29+
print >> sys.stderr, "Failed to setup thread-interrupt handler. This is usually not critical"
30+
# END exception handling
2531

2632

2733
#} END init

0 commit comments

Comments
 (0)