File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 1- import ctypes
21import pytest
32import threading
3+ import time
44
55import sergeant .slave
66
77
8+ def sleep_thread ():
9+ while True :
10+ time .sleep (0.3 )
11+
12+
813@pytest .fixture
914def background_threads ():
10- threads = [threading .Thread (target = threading ._DummyThread , daemon = False ) for _ in range (3 )]
15+ dummy_thread = threading ._DummyThread ()
16+
17+ threads = [threading .Thread (target = sleep_thread ) for _ in range (3 )]
1118
1219 for thread in threads :
1320 thread .start ()
1421
15- yield threads
22+ threads . append ( dummy_thread )
1623
17- for thread in threads :
18- if thread .is_alive ():
19- ctypes .pythonapi .PyThreadState_SetAsyncExc (
20- ctypes .c_ulong (thread .ident ),
21- ctypes .py_object (SystemExit ),
22- )
23- thread .join ()
24+ yield threads
2425
2526
2627def test_kill_running_background_threads (
@@ -29,4 +30,5 @@ def test_kill_running_background_threads(
2930 assert sergeant .slave .kill_running_background_threads () is True
3031
3132 for thread in background_threads :
32- assert not thread .is_alive ()
33+ if not isinstance (thread , threading ._DummyThread ):
34+ assert not thread .is_alive ()
You can’t perform that action at this time.
0 commit comments