File tree Expand file tree Collapse file tree 3 files changed +56
-4
lines changed
Expand file tree Collapse file tree 3 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ def kill_running_background_threads() -> bool:
9999 if thread is threading .main_thread ():
100100 continue
101101
102- if thread .ident :
102+ if thread .ident and not isinstance ( thread , threading . _DummyThread ) :
103103 ctypes .pythonapi .PyThreadState_SetAsyncExc (
104104 ctypes .c_ulong (thread .ident ),
105105 ctypes .py_object (SystemExit ),
Original file line number Diff line number Diff line change @@ -11,13 +11,29 @@ services:
1111 - 6380:6379
1212 mongo-node-one :
1313 image : mongo
14+ restart : always
1415 ports :
1516 - 27017:27017
1617 command : >
17- mongod --port 27017 --replSet test_replica_set --bind_ip_all
18+ mongod --replSet test_replica_set --bind_ip_all
19+ container_name : mongo-one
20+ volumes :
21+ - mongo1_data:/data/db
22+
1823 mongo-node-two :
1924 image : mongo
25+ restart : always
2026 ports :
21- - 27018:27018
27+ - 27018:27017
2228 command : >
23- mongod --port 27018 --replSet test_replica_set --bind_ip_all
29+ mongod --replSet test_replica_set --bind_ip_all
30+ container_name : mongo-two
31+ volumes :
32+ - mongo2_data:/data/db
33+
34+
35+ volumes :
36+ mongo1_data :
37+ driver : local
38+ mongo2_data :
39+ driver : local
Original file line number Diff line number Diff line change 1+ import ctypes
2+ import pytest
3+ import threading
4+ import time
5+
6+ import sergeant .slave
7+
8+
9+ def dummy_thread ():
10+ while True :
11+ time .sleep (0.1 )
12+
13+
14+ @pytest .fixture
15+ def background_threads ():
16+ threads = [threading .Thread (target = dummy_thread , daemon = False ) for _ in range (3 )]
17+
18+ for thread in threads :
19+ thread .start ()
20+
21+ yield threads
22+
23+ for thread in threads :
24+ if thread .is_alive ():
25+ ctypes .pythonapi .PyThreadState_SetAsyncExc (
26+ ctypes .c_ulong (thread .ident ),
27+ ctypes .py_object (SystemExit ),
28+ )
29+ thread .join ()
30+
31+
32+ def test_kill_running_background_threads (background_threads ):
33+ assert sergeant .slave .kill_running_background_threads () is True
34+
35+ for thread in background_threads :
36+ assert not thread .is_alive ()
You can’t perform that action at this time.
0 commit comments