From e1716581a4bcb4493ddba1e6f5d180f4a638e606 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Thu, 14 Nov 2024 03:51:14 +0000 Subject: [PATCH] fix: race condition in pruning thread pool --- a_sync/executor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/a_sync/executor.py b/a_sync/executor.py index cb731961..62f2037d 100644 --- a/a_sync/executor.py +++ b/a_sync/executor.py @@ -324,7 +324,9 @@ def _worker( with executor._adjusting_lock: # NOTE: NEW # NOTE: We keep a minimum of one thread active to prevent locks - if len(executor) > 1: # NOTE: NEW + if len(executor) > 1 or executor._idle_semaphore.acquire( + blocking=False + ): # NOTE: NEW t = threading.current_thread() # NOTE: NEW executor._threads.remove(t) # NOTE: NEW thread._threads_queues.pop(t) # NOTE: NEW