Skip to content

Commit 7bd3ef4

Browse files
🪲 BUG-#131: Fix timeout thread leak by using shutdown(wait=False, cancel_futures=True)
1 parent 810264c commit 7bd3ef4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎dotflow/core/action.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,21 @@ def _run_action(self, *args, task=None, **kwargs):
144144
for attempt in range(1, self.retry + 1):
145145
try:
146146
if self.timeout:
147-
with ThreadPoolExecutor(max_workers=1) as executor:
147+
executor = ThreadPoolExecutor(max_workers=1)
148+
try:
148149
future = executor.submit(
149150
self._call_func,
150151
is_async,
151152
*args,
152153
**kwargs,
153154
)
154155
result = future.result(timeout=self.timeout)
156+
except TimeoutError:
157+
future.cancel()
158+
executor.shutdown(wait=False, cancel_futures=True)
159+
raise
160+
else:
161+
executor.shutdown(wait=False)
155162
else:
156163
result = self._call_func(is_async, *args, **kwargs)
157164

0 commit comments

Comments
 (0)