Skip to content

Commit 65dbe3d

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 6d1c4a1 commit 65dbe3d

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
@@ -274,7 +274,13 @@ def __init__(
274274
logger.info("TaskHandler initialized")
275275

276276
def __enter__(self):
277-
self.start_processes()
277+
try:
278+
self.start_processes()
279+
except BaseException:
280+
# __exit__ is not called if __enter__ raises, so clean up any
281+
# partially-spawned workers here before propagating.
282+
self.stop_processes()
283+
raise
278284
return self
279285

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

0 commit comments

Comments
 (0)