Skip to content

Commit be52890

Browse files
committed
Run cleanup in a separate daemon thread for timeout handling in TimeoutMixin
1 parent d645a8f commit be52890

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llm_sandbox/core/mixins.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ def target() -> None:
107107
# Optional: Force container-level kill for true cancellation
108108
handler = getattr(self, "_handle_timeout", None)
109109
if force_kill_on_timeout and callable(handler):
110-
try:
111-
handler() # pyright: ignore[reportAttributeAccess]
112-
except Exception: # noqa: BLE001
113-
self.logger.warning("Failed to cleanup container after timeout")
110+
111+
def cleanup_async() -> None:
112+
try:
113+
handler() # pyright: ignore[reportAttributeAccess]
114+
except Exception: # noqa: BLE001
115+
self.logger.warning("Failed to cleanup container after timeout")
116+
117+
# Run cleanup in a separate daemon thread to avoid blocking
118+
cleanup_thread = threading.Thread(target=cleanup_async, daemon=True)
119+
cleanup_thread.start()
114120

115121
raise SandboxTimeoutError(msg, timeout_duration=timeout)
116122

0 commit comments

Comments
 (0)