Skip to content

Commit a288db1

Browse files
chore: call sandbox.close() instead of internal functions (#22)
This makes the cleanup logic easier to reason about
1 parent aab270b commit a288db1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/deno_sandbox/sandbox.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@ async def create(
184184
if sandbox_id is None:
185185
raise Exception("Sandbox ID not found in response headers")
186186

187+
sandbox = None
187188
try:
188189
rpc = AsyncRpcClient(transport)
189-
yield AsyncSandbox(self._client, rpc, sandbox_id)
190+
sandbox = AsyncSandbox(self._client, rpc, sandbox_id)
191+
yield sandbox
190192
finally:
191-
await transport.close()
193+
if sandbox is not None:
194+
await sandbox.close()
192195

193196
@asynccontextmanager
194197
async def connect(
@@ -210,11 +213,14 @@ async def connect(
210213
},
211214
)
212215

216+
sandbox = None
213217
try:
214218
rpc = AsyncRpcClient(transport)
215-
yield AsyncSandbox(self._client, rpc, sandbox_id)
219+
sandbox = AsyncSandbox(self._client, rpc, sandbox_id)
220+
yield sandbox
216221
finally:
217-
await transport.close()
222+
if sandbox is not None:
223+
await sandbox.close()
218224

219225
async def list(
220226
self, options: Optional[SandboxListOptions] = None

0 commit comments

Comments
 (0)