Skip to content

Commit

Permalink
ignore comm_open, comm_msg and comm_close messages (plus black changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbarratt committed Jan 1, 2023
1 parent 576152e commit 31fc51e
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions custom_components/pyscript/jupyter_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def __init__(self, config, ast_ctx, global_ctx, global_ctx_name):
self.no_connect_timeout = self.config.get("no_connect_timeout", 30)
self.signature_schemes = {"hmac-sha256": hashlib.sha256}
self.auth = hmac.HMAC(
self.secure_key, digestmod=self.signature_schemes[self.config["signature_scheme"]],
self.secure_key,
digestmod=self.signature_schemes[self.config["signature_scheme"]],
)
self.execution_count = 1
self.engine_id = str(uuid.uuid4())
Expand Down Expand Up @@ -295,7 +296,13 @@ def new_header(self, msg_type):
}

async def send(
self, stream, msg_type, content=None, parent_header=None, metadata=None, identities=None,
self,
stream,
msg_type,
content=None,
parent_header=None,
metadata=None,
identities=None,
):
"""Send message to the Jupyter client."""
header = self.new_header(msg_type)
Expand Down Expand Up @@ -401,7 +408,10 @@ async def shell_handler(self, shell_socket, wire_msg):
"metadata": {},
}
await self.send(
self.iopub_socket, "execute_result", content, parent_header=msg["header"],
self.iopub_socket,
"execute_result",
content,
parent_header=msg["header"],
)

metadata = {
Expand Down Expand Up @@ -484,7 +494,11 @@ async def shell_handler(self, shell_socket, wire_msg):
"metadata": {},
}
await self.send(
shell_socket, "complete_reply", content, parent_header=msg["header"], identities=identities,
shell_socket,
"complete_reply",
content,
parent_header=msg["header"],
identities=identities,
)

elif msg["header"]["msg_type"] == "is_complete_request":
Expand Down Expand Up @@ -546,15 +560,26 @@ async def shell_handler(self, shell_socket, wire_msg):
elif msg["header"]["msg_type"] == "comm_info_request":
content = {"comms": {}}
await self.send(
shell_socket, "comm_info_reply", content, parent_header=msg["header"], identities=identities,
shell_socket,
"comm_info_reply",
content,
parent_header=msg["header"],
identities=identities,
)

elif msg["header"]["msg_type"] == "history_request":
content = {"history": []}
await self.send(
shell_socket, "history_reply", content, parent_header=msg["header"], identities=identities,
shell_socket,
"history_reply",
content,
parent_header=msg["header"],
identities=identities,
)

elif msg["header"]["msg_type"] in {"comm_open", "comm_msg", "comm_close"}:
# _LOGGER.debug(f"ignore {msg['header']['msg_type']} message ")
...
else:
_LOGGER.error("unknown msg_type: %s", msg["header"]["msg_type"])

Expand Down Expand Up @@ -752,7 +777,9 @@ async def start_one_server(self, callback):
except OSError:
self.avail_port += 1
_LOGGER.error(
"unable to find an available port from %d to %d", first_port, self.avail_port - 1,
"unable to find an available port from %d to %d",
first_port,
self.avail_port - 1,
)
return None, None

Expand Down

0 comments on commit 31fc51e

Please sign in to comment.