Skip to content

Commit

Permalink
Make Qtconsole work with PyZMQ 25 (#914)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 12, 2023
1 parent 1f8bed3 commit 2ee33ce
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions jupyter_client/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(
def setup_stream():
assert self.socket is not None
self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
self.stream.on_recv(self._handle_recv) # type:ignore[arg-type]
self.stream.on_recv(self._handle_recv)
evt.set()

assert self.ioloop is not None
Expand Down Expand Up @@ -115,21 +115,24 @@ def thread_send():
assert self.ioloop is not None
self.ioloop.add_callback(thread_send)

def _handle_recv(self, future_msg: Awaitable) -> None:
def _handle_recv(self, msg: Union[List[bytes], Awaitable]) -> None:
"""Callback for stream.on_recv.
Unpacks message, and calls handlers with it.
"""
assert self.ioloop is not None
loop = self.ioloop._asyncio_event_loop # type:ignore[attr-defined]
msg_list = loop.run_until_complete(get_msg(future_msg))
if asyncio.isfuture(msg):
assert self.ioloop is not None
loop = self.ioloop._asyncio_event_loop # type:ignore[attr-defined]
msg_list = loop.run_until_complete(get_msg(msg))
else:
msg_list = msg
assert self.session is not None
ident, smsg = self.session.feed_identities(msg_list)
msg = self.session.deserialize(smsg)
new_msg = self.session.deserialize(smsg)
# let client inspect messages
if self._inspect:
self._inspect(msg)
self.call_handlers(msg)
self._inspect(new_msg)
self.call_handlers(new_msg)

def call_handlers(self, msg: Dict[str, Any]) -> None:
"""This method is called in the ioloop thread when a message arrives.
Expand Down

0 comments on commit 2ee33ce

Please sign in to comment.