fix(tools): adapt DaemonThreadPoolExecutor for Python 3.14 _worker signature - #58598
fix(tools): adapt DaemonThreadPoolExecutor for Python 3.14 _worker signature#58598liuhao1024 wants to merge 1 commit into
Conversation
…gnature Python 3.14 changed concurrent.futures.thread._worker from 4 params (executor_ref, work_queue, initializer, initargs) to 3 params (executor_ref, ctx, work_queue), replacing instance-level self._initializer/self._initargs with a WorkerContext created via self._create_worker_context(). Detect the signature at import time via inspect.signature and branch _args accordingly. Preserves daemon=True and no _threads_queues registration semantics. Fixes NousResearch#58596
Duplicate of #57459 — both PRs fix the same crash in Related: #58596 (the issue), #50077 / #47634 (same 3.14 theme but a different file, |
|
Closing as a self-duplicate of #57459 — both fix the same |
What does this PR do?
Fixes
DaemonThreadPoolExecutorcrash on Python 3.14 where_adjust_thread_count()referencesself._initializerandself._initargs, which no longer exist. Python 3.14 changedconcurrent.futures.thread._workerfrom 4 params to 3, replacing(initializer, initargs)with aWorkerContextobject created viaself._create_worker_context().Related Issue
Fixes #58596
Type of Change
Changes Made
tools/daemon_pool.py: Detect_workersignature at import time (inspect.signature, 3 vs 4 params) and branch_adjust_thread_countargs accordingly. Python ≥3.14 passesself._create_worker_context()as the ctx argument; ≤3.13 passesself._initializer/self._initargs.tests/tools/test_daemon_pool.py: Addedtest_worker_signature_detection_matches_runtime(verifies_WORKER_USES_CTXmatches runtime_workerparam count) andtest_concurrent_submit_with_context_path(10 concurrent submits under the ctx-based path).How to Test
python -m pytest tests/tools/test_daemon_pool.py -v— all 6 tests should passpython -c "from tools.daemon_pool import DaemonThreadPoolExecutor; e = DaemonThreadPoolExecutor(max_workers=1); print(e.submit(lambda: 42).result())"should print42(previously crashed withAttributeError)_workerpathChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/tools/test_daemon_pool.py -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A