Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tools/daemon_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from __future__ import annotations

import sys
import threading
import weakref
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -38,8 +39,10 @@ class DaemonThreadPoolExecutor(ThreadPoolExecutor):
"""ThreadPoolExecutor variant whose workers do not block process exit."""

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.
# Python 3.14 removed _initializer / _initargs, replacing them
# with _create_worker_context() and a 3-arg _worker signature.
if self._idle_semaphore.acquire(timeout=0):
return

Expand All @@ -49,15 +52,23 @@ def weakref_cb(_, q=self._work_queue):
num_threads = len(self._threads)
if num_threads < self._max_workers:
thread_name = "%s_%d" % (self._thread_name_prefix or self, num_threads)
t = threading.Thread(
name=thread_name,
target=_worker,
args=(
if sys.version_info >= (3, 14):
worker_args = (
weakref.ref(self, weakref_cb),
self._create_worker_context(),
self._work_queue,
)
else:
worker_args = (
weakref.ref(self, weakref_cb),
self._work_queue,
self._initializer,
self._initargs,
),
)
t = threading.Thread(
name=thread_name,
target=_worker,
args=worker_args,
daemon=True,
)
t.start()
Expand Down
Loading