Skip to content

Commit 1b2b029

Browse files
committed
make create process session robust
1 parent c83f52b commit 1b2b029

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

aide/interpreter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def cleanup_session(self):
184184
if self.process is None:
185185
return
186186
try:
187-
# Reduce grace period from 2 seconds to 0.5
187+
# total grace period = 8 seconds
188188
self.process.terminate()
189189
self.process.join(timeout=2)
190190

@@ -196,12 +196,16 @@ def cleanup_session(self):
196196
if self.process.exitcode is None:
197197
logger.error("Process refuses to die, using SIGKILL")
198198
os.kill(self.process.pid, signal.SIGKILL)
199+
self.process.join(timeout=4)
199200
except Exception as e:
200201
logger.error(f"Error during process cleanup: {e}")
201202
finally:
202203
if self.process is not None:
203-
self.process.close()
204-
self.process = None
204+
try:
205+
self.process.close() # still try to close
206+
except ValueError:
207+
logger.error("Skipping close: child stuck in D-state")
208+
self.process = None
205209

206210
def run(self, code: str, reset_session=True) -> ExecutionResult:
207211
"""

0 commit comments

Comments
 (0)