Skip to content

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Darshan808 committed Jan 15, 2025
1 parent 9f94617 commit 535e241
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion jupyter_server_nbmodel/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ def initialize_handlers(self):
async def stop_extension(self):
if hasattr(self, "__execution_stack"):
get_logger().info("Disposing the execution stack…")
await self.__execution_stack.dispose()
await asyncio.wait_for(self.__execution_stack.dispose(), timeout=3)
13 changes: 7 additions & 6 deletions jupyter_server_nbmodel/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ async def _execute_snippet(
if metadata is not None:
ycell = await _get_ycell(ydoc, metadata)
if ycell is not None:
execution_start_time = datetime.now(timezone.utc).isoformat()[:-6]
# Reset cell
with ycell.doc.transaction():
del ycell["outputs"][:]
ycell["execution_count"] = None
ycell["execution_state"] = "running"
if metadata.get("record_timing", False):
time_info = ycell["metadata"].get("execution", {})
time_info["shell.execute_reply.started"] = datetime.now(timezone.utc).isoformat()[:-6]
time_info["shell.execute_reply.started"] = execution_start_time
ycell["metadata"]["execution"] = time_info
# Emit cell execution start event
event_logger.emit(
Expand All @@ -248,7 +249,7 @@ async def _execute_snippet(
"event_type": "execution_start",
"cell_id": metadata["cell_id"],
"document_id": metadata["document_id"],
"timestamp": datetime.now(timezone.utc).isoformat()
"timestamp": execution_start_time
}
)
outputs = []
Expand All @@ -267,15 +268,15 @@ async def _execute_snippet(
reply_content = reply["content"]

if ycell is not None:
execution_end_time = datetime.now(timezone.utc).isoformat()[:-6]
with ycell.doc.transaction():
ycell["execution_count"] = reply_content.get("execution_count")
ycell["execution_state"] = "idle"
if metadata and metadata.get("record_timing", False):
end_time = datetime.now(timezone.utc).isoformat()[:-6]
if reply_content["status"] == "ok":
time_info["shell.execute_reply"] = end_time
time_info["shell.execute_reply"] = execution_end_time
else:
time_info["execution_failed"] = end_time
time_info["execution_failed"] = execution_end_time
ycell["metadata"]["execution"] = time_info
# Emit cell execution end event
event_logger.emit(
Expand All @@ -286,7 +287,7 @@ async def _execute_snippet(
"document_id": metadata["document_id"],
"success": reply_content["status"]=="ok",
"kernel_error": _get_error(outputs),
"timestamp": datetime.now(timezone.utc).isoformat()
"timestamp": execution_end_time
}
)
return {
Expand Down

0 comments on commit 535e241

Please sign in to comment.