Skip to content

Commit 8dc50e9

Browse files
authored
Merge pull request #154 from pytest-dev/only_set_signals_in_main_thread
Avoid setting signals when not in main thread (and warn)
2 parents a488312 + 24809c4 commit 8dc50e9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pytest_twisted.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import itertools
44
import signal
55
import sys
6+
import threading
67
import warnings
78

89
import decorator
@@ -200,7 +201,16 @@ def init_twisted_greenlet():
200201
return
201202

202203
if not _instances.reactor.running:
203-
if signal.getsignal(signal.SIGINT) == signal.default_int_handler:
204+
if not isinstance(threading.current_thread(), threading._MainThread):
205+
warnings.warn(
206+
(
207+
'Will not attempt to block Twisted signal configuration'
208+
' since we are not running in the main thread. See'
209+
' https://github.com/pytest-dev/pytest-twisted/issues/153.'
210+
),
211+
RuntimeWarning,
212+
)
213+
elif signal.getsignal(signal.SIGINT) == signal.default_int_handler:
204214
signal.signal(
205215
signal.SIGINT,
206216
functools.partial(signal.default_int_handler),

0 commit comments

Comments
 (0)