Skip to content

Commit 6ce9ddf

Browse files
committed
fixed CR items
1 parent 783f35d commit 6ce9ddf

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import ctypes
21
import pytest
32
import threading
3+
import time
44

55
import sergeant.slave
66

77

8+
def sleep_thread():
9+
while True:
10+
time.sleep(0.3)
11+
12+
813
@pytest.fixture
914
def 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

2627
def 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()

0 commit comments

Comments
 (0)