Skip to content

Commit 3ffc693

Browse files
Fix: inverted logic in Modal sandbox termination (#278)
* Fix ModalDeployment.stop logic to verify sandbox is running * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e12ab55 commit 3ffc693

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/swerex/deployment/modal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ async def stop(self):
251251
await self._runtime.close()
252252
self._runtime = None
253253
if self._sandbox is not None:
254+
# Check if the sandbox is still running
254255
exit_code = await self._sandbox.poll.aio()
255-
if exit_code is not None:
256+
257+
# If exit_code is None, the process is still active -> Terminate it
258+
if exit_code is None:
259+
self.logger.info(f"Terminating sandbox {self._sandbox.object_id}...")
256260
await self._sandbox.terminate.aio()
257261
self._sandbox = None
258262
self._app = None

src/swerex/runtime/local.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
__all__ = ["LocalRuntime", "BashSession"]
5656

5757

58-
def _split_bash_command(inpt: str) -> list[str]:
58+
def _split_bash_command(input: str) -> list[str]:
5959
r"""Split a bash command with linebreaks, escaped newlines, and heredocs into a list of
6060
individual commands.
6161
6262
Args:
63-
inpt: The input string to split into commands.
63+
input: The input string to split into commands.
6464
Returns:
6565
A list of commands as strings.
6666
@@ -70,11 +70,11 @@ def _split_bash_command(inpt: str) -> list[str]:
7070
"cmd1\\\n asdf" is one command (because the linebreak is escaped)
7171
"cmd1<<EOF\na\nb\nEOF" is one command (because of the heredoc)
7272
"""
73-
inpt = inpt.strip()
74-
if not inpt or all(l.strip().startswith("#") for l in inpt.splitlines()):
73+
input = input.strip()
74+
if not input or all(l.strip().startswith("#") for l in input.splitlines()):
7575
# bashlex can't deal with empty strings or the like :/
7676
return []
77-
parsed = bashlex.parse(inpt)
77+
parsed = bashlex.parse(input)
7878
cmd_strings = []
7979

8080
def find_range(cmd: bashlex.ast.node) -> tuple[int, int]:
@@ -88,7 +88,7 @@ def find_range(cmd: bashlex.ast.node) -> tuple[int, int]:
8888

8989
for cmd in parsed:
9090
start, end = find_range(cmd)
91-
cmd_strings.append(inpt[start:end])
91+
cmd_strings.append(input[start:end])
9292
return cmd_strings
9393

9494

0 commit comments

Comments
 (0)