Skip to content

Commit 569dac2

Browse files
committed
🔧 fix session_id management
1 parent d055d2b commit 569dac2

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

codeboxapi/box/codebox.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ async def astart(self) -> CodeBoxStatus:
126126
if settings.VERBOSE:
127127
print(f"{self} is already started!")
128128
return CodeBoxStatus(status="started")
129-
self.session_id = (
130-
await abase_request(
131-
self.aiohttp_session,
132-
method="GET",
133-
endpoint="/codebox/start",
134-
)
135-
)["id"]
129+
self.session_id = UUID(
130+
int=(
131+
await abase_request(
132+
self.aiohttp_session, method="GET", endpoint="/codebox/start"
133+
)
134+
)["id"]
135+
)
136136
if settings.VERBOSE:
137137
print(f"{self} started!")
138138
return CodeBoxStatus(status="started")
@@ -287,12 +287,14 @@ async def arestart(self) -> CodeBoxStatus:
287287
)
288288

289289
def stop(self) -> CodeBoxStatus:
290-
return CodeBoxStatus(
290+
status = CodeBoxStatus(
291291
**self.codebox_request(
292292
method="POST",
293293
endpoint="/stop",
294294
)
295295
)
296+
self.session_id = None
297+
return status
296298

297299
async def astop(self) -> CodeBoxStatus:
298300
status = CodeBoxStatus(
@@ -301,6 +303,7 @@ async def astop(self) -> CodeBoxStatus:
301303
endpoint="/stop",
302304
)
303305
)
306+
self.session_id = None
304307
if self.aiohttp_session:
305308
await self.aiohttp_session.close()
306309
self.aiohttp_session = None

codeboxapi/box/localbox.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,17 @@ async def arestart(self) -> CodeBoxStatus:
506506
return CodeBoxStatus(status="restarted")
507507

508508
def stop(self) -> CodeBoxStatus:
509-
for pid in self._jupyter_pids:
510-
print(f"Killing {pid}")
511-
os.kill(pid, signal.SIGTERM)
512-
513-
if self.jupyter is not None:
514-
self.jupyter.terminate()
515-
self.jupyter.wait()
516-
self.jupyter = None
517-
time.sleep(2)
509+
try:
510+
if self.jupyter is not None:
511+
self.jupyter.terminate()
512+
self.jupyter.wait()
513+
self.jupyter = None
514+
time.sleep(2)
515+
else:
516+
for pid in self._jupyter_pids:
517+
os.kill(pid, signal.SIGTERM)
518+
except ProcessLookupError:
519+
pass
518520

519521
if self.ws is not None:
520522
try:

0 commit comments

Comments
 (0)