Skip to content

Commit 19d05a9

Browse files
committed
fix: clean up partial workers if start_processes fails in __enter__
Python skips __exit__ when __enter__ raises, so an exception mid-startup would leak any workers already spawned. Wrap the call so stop_processes() runs before the exception propagates.
1 parent 6da785e commit 19d05a9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/conductor/client/automator/task_handler.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,13 @@ def __init__(
329329
logger.info("TaskHandler initialized")
330330

331331
def __enter__(self):
332-
self.start_processes()
332+
try:
333+
self.start_processes()
334+
except BaseException:
335+
# __exit__ is not called if __enter__ raises, so clean up any
336+
# partially-spawned workers here before propagating.
337+
self.stop_processes()
338+
raise
333339
return self
334340

335341
def __exit__(self, exc_type, exc_value, traceback):

0 commit comments

Comments
 (0)