14
14
import time
15
15
import threading
16
16
import traceback
17
+ import pytest
17
18
from collections import namedtuple
18
19
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
22
20
23
21
import py
24
22
import pytest
@@ -200,7 +198,9 @@ def timeout_setup(item):
200
198
return
201
199
202
200
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
+ ):
204
204
timeout_method = "thread"
205
205
206
206
if timeout_method == "signal" :
@@ -216,7 +216,10 @@ def cancel():
216
216
signal .signal (signal .SIGALRM , handler )
217
217
signal .setitimer (signal .ITIMER_REAL , params .timeout )
218
218
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
+ )
220
223
timer .name = "%s %s" % (__name__ , item .nodeid )
221
224
222
225
def cancel ():
@@ -424,13 +427,13 @@ def timeout_timer(item, timeout, thread):
424
427
sys .stdout .flush ()
425
428
sys .stderr .flush ()
426
429
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 )
432
435
433
- os ._exit (1 )
436
+ os ._exit (1 )
434
437
435
438
436
439
def dump_stacks ():
0 commit comments