Skip to content

Commit 09524aa

Browse files
committed
use thread method if not main thread
fixes #8
1 parent c311f7a commit 09524aa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ session using ```--pdb``` or similar.
218218
Changelog
219219
=========
220220

221+
2.0.0
222+
-----
223+
224+
- Use thread timeout method when plugin is not called from main
225+
thread to avoid crash.
226+
221227
1.4.2
222228
-----
223229

pytest_timeout.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ 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":
196+
197+
timeout_method = params.method
198+
if (
199+
timeout_method == "signal"
200+
and threading.current_thread() is not threading.main_thread()
201+
):
202+
timeout_method = "thread"
203+
204+
if timeout_method == "signal":
197205

198206
def handler(signum, frame):
199207
__tracebackhide__ = True
@@ -206,7 +214,7 @@ def cancel():
206214
item.cancel_timeout = cancel
207215
signal.signal(signal.SIGALRM, handler)
208216
signal.setitimer(signal.ITIMER_REAL, params.timeout)
209-
elif params.method == "thread":
217+
elif timeout_method == "thread":
210218
timer = threading.Timer(params.timeout, timeout_timer, (item, params.timeout))
211219
timer.name = "%s %s" % (__name__, item.nodeid)
212220

0 commit comments

Comments
 (0)