Skip to content

Commit 70df295

Browse files
committed
refactor: Keep the pool's max_workers instead of reading ThreadPoolExecutor's private copy
1 parent 0a01d27 commit 70df295

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎cloudquery/sdk/scheduler/scheduler.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121

2222
class ThreadPoolExecutorWithQueueSizeLimit(futures.ThreadPoolExecutor):
23-
def __init__(self, maxsize, *args, **kwargs):
24-
super().__init__(*args, **kwargs)
23+
def __init__(self, maxsize: int, max_workers: int, *args, **kwargs):
24+
super().__init__(max_workers, *args, **kwargs)
2525
self.maxsize = maxsize
26-
self._slots = threading.BoundedSemaphore(maxsize + self._max_workers)
26+
# submit() puts on the work queue while holding a lock that every pool shares, so a
27+
# full bounded queue would block the other pools' workers too: limit it before submit
28+
self._slots = threading.BoundedSemaphore(maxsize + max_workers)
2729

2830
def submit(self, fn, /, *args, **kwargs):
2931
self._slots.acquire()

0 commit comments

Comments
 (0)