fix(tools): support daemon pool workers on Python 3.14

Cherry-picked from #111814. The same feature-detected fix was proposed earlier in
#58699, #65182 and #57459 (final form).

Co-authored-by: nankingjing <76432572+nankingjing@users.noreply.github.com>
Co-authored-by: TheNeuralVault <jdkabattles@gmail.com>
Co-authored-by: gongyi <yigongsyl@gmail.com>
This commit is contained in:
KoNit-K
2026-09-15 18:31:09 +08:00
committed by Teknium
parent 4c4d54554d
commit c9fa191334
2 changed files with 41 additions and 2 deletions
+18 -2
View File
@@ -36,7 +36,7 @@ class DaemonThreadPoolExecutor(ThreadPoolExecutor):
return super().submit(_run_with_context, *args, **kwargs)
def _adjust_thread_count(self) -> None:
# Mirrors CPython's implementation (3.8–3.13) with two changes:
# Mirrors CPython's implementation with two changes:
# daemon=True and no _threads_queues registration.
if self._idle_semaphore.acquire(timeout=0):
return
@@ -46,11 +46,27 @@ class DaemonThreadPoolExecutor(ThreadPoolExecutor):
num_threads = len(self._threads)
if num_threads < self._max_workers:
thread_name = "%s_%d" % (self._thread_name_prefix or self, num_threads)
executor_ref = weakref.ref(self, weakref_cb)
if hasattr(self, "_create_worker_context"):
# Python 3.14 replaced _initializer/_initargs with a factory
# that supplies the worker's initializer context.
worker_args = (
executor_ref,
self._create_worker_context(),
self._work_queue,
)
else:
worker_args = (
executor_ref,
self._work_queue,
self._initializer,
self._initargs,
)
# Carry the active profile into the review thread so MEMORY.md / skill review writes land in the
# right profile (#54937).
t = threading.Thread(
name=thread_name, target=_worker, daemon=True,
args=(weakref.ref(self, weakref_cb), self._work_queue, self._initializer, self._initargs),
args=worker_args,
)
t.start()
self._threads.add(t)