Skip to content

Commit b12a248

Browse files
authored
Avoid setting signals when not in main thread (and warn)
#153
1 parent a488312 commit b12a248

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pytest_twisted.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,16 @@ def init_twisted_greenlet():
200200
return
201201

202202
if not _instances.reactor.running:
203-
if signal.getsignal(signal.SIGINT) == signal.default_int_handler:
203+
if not isinstance(threading.current_thread(), threading._MainThread):
204+
warnings.warn(
205+
(
206+
'Failed to block Twisted signal configuration due to not running in the main thread.'
207+
' See https://github.com/pytest-dev/pytest-twisted/issues/153.'
208+
209+
),
210+
RuntimeWarning,
211+
)
212+
elif signal.getsignal(signal.SIGINT) == signal.default_int_handler:
204213
signal.signal(
205214
signal.SIGINT,
206215
functools.partial(signal.default_int_handler),

0 commit comments

Comments
 (0)