Skip to content

Commit ae8de81

Browse files
committed
Rewrite a thread shim for compatibility with python 3.14+
1 parent e495b41 commit ae8de81

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

hstest/common/process_utils.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import threading
44
import weakref
55
from concurrent.futures import ThreadPoolExecutor
6-
from concurrent.futures.thread import _worker
6+
from concurrent.futures.thread import _worker, _threads_queues
77
from typing import TYPE_CHECKING
88

99
if TYPE_CHECKING:
@@ -29,17 +29,26 @@ def weakref_cb(_, q=self._work_queue) -> None:
2929
if num_threads < self._max_workers:
3030
thread_name = "%s_%d" % (self._thread_name_prefix or self, num_threads)
3131

32-
args = (
33-
weakref.ref(self, weakref_cb),
34-
self._work_queue,
35-
self._initializer,
36-
self._initargs,
37-
)
38-
39-
t = threading.Thread(name=thread_name, target=_worker, args=args, group=self.group)
32+
# Python 3.14+ refactored initializer/initargs into WorkerContext
33+
if hasattr(self, "_create_worker_context"):
34+
args = (
35+
weakref.ref(self, weakref_cb),
36+
self._create_worker_context(),
37+
self._work_queue,
38+
)
39+
else:
40+
args = (
41+
weakref.ref(self, weakref_cb),
42+
self._work_queue,
43+
self._initializer,
44+
self._initargs,
45+
)
46+
47+
t = threading.Thread(name=thread_name, target=_worker, args=args)
4048
t.daemon = True
4149
t.start()
4250
self._threads.add(t)
51+
_threads_queues[t] = self._work_queue
4352

4453

4554
def is_port_in_use(port):

0 commit comments

Comments
 (0)