Skip to content

Commit 20f7a3a

Browse files
committed
fixup
1 parent dfb4b20 commit 20f7a3a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ docs/_build/
5858

5959
# IDE
6060
.idea
61+
.vscode

pytest_timeout.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
import time
1515
import threading
1616
import traceback
17+
import pytest
1718
from collections import namedtuple
1819
from distutils.version import LooseVersion
19-
from threading import current_thread, main_thread
20-
from _pytest.config import ExitCode
21-
from _pytest.outcomes import Failed
2220

2321
import py
2422
import pytest
@@ -200,7 +198,9 @@ def timeout_setup(item):
200198
return
201199

202200
timeout_method = params.method
203-
if timeout_method == "signal" and not (current_thread() is main_thread()):
201+
if timeout_method == "signal" and (
202+
threading.current_thread() is not threading.main_thread()
203+
):
204204
timeout_method = "thread"
205205

206206
if timeout_method == "signal":
@@ -216,7 +216,10 @@ def cancel():
216216
signal.signal(signal.SIGALRM, handler)
217217
signal.setitimer(signal.ITIMER_REAL, params.timeout)
218218
elif timeout_method == "thread":
219-
timer = threading.Timer(params.timeout, timeout_timer, (item, params.timeout, current_thread()))
219+
timer = threading.Timer(
220+
params.timeout, timeout_timer,
221+
(item, params.timeout, threading.current_thread()),
222+
)
220223
timer.name = "%s %s" % (__name__, item.nodeid)
221224

222225
def cancel():
@@ -424,13 +427,13 @@ def timeout_timer(item, timeout, thread):
424427
sys.stdout.flush()
425428
sys.stderr.flush()
426429

427-
for _ in range(10):
428-
ctypes.pythonapi.PyThreadState_SetAsyncExc(
429-
ctypes.c_long(thread.ident), ctypes.py_object(Failed),
430-
)
431-
time.sleep(0.5)
430+
for _ in range(10):
431+
ctypes.pythonapi.PyThreadState_SetAsyncExc(
432+
ctypes.c_long(thread.ident), ctypes.py_object(pytest.fail.Exception),
433+
)
434+
time.sleep(0.5)
432435

433-
os._exit(1)
436+
os._exit(1)
434437

435438

436439
def dump_stacks():

0 commit comments

Comments
 (0)