Skip to content

Commit 718682d

Browse files
committed
use thread method if not main thread
fixes pytest-dev#8
1 parent c311f7a commit 718682d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: pytest_timeout.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,13 @@ def timeout_setup(item):
193193
params = get_params(item)
194194
if params.timeout is None or params.timeout <= 0:
195195
return
196-
if params.method == "signal":
197196

197+
timeout_method = params.method
198+
if (timeout_method == "signal"
199+
and threading.current_thread() is not threading.main_thread()):
200+
timeout_method = "thread"
201+
202+
if timeout_method == "signal":
198203
def handler(signum, frame):
199204
__tracebackhide__ = True
200205
timeout_sigalrm(item, params.timeout)
@@ -206,7 +211,7 @@ def cancel():
206211
item.cancel_timeout = cancel
207212
signal.signal(signal.SIGALRM, handler)
208213
signal.setitimer(signal.ITIMER_REAL, params.timeout)
209-
elif params.method == "thread":
214+
elif timeout_method == "thread":
210215
timer = threading.Timer(params.timeout, timeout_timer, (item, params.timeout))
211216
timer.name = "%s %s" % (__name__, item.nodeid)
212217

0 commit comments

Comments
 (0)