Skip to content

Commit

Permalink
Fix in-process kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Apr 7, 2022
1 parent f81f481 commit 4e5b833
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import zmq
from jupyter_client.session import extract_header
from zmq.eventloop.zmqstream import ZMQStream
from .zmqstream import ZMQStream

# -----------------------------------------------------------------------------
# Globals
Expand Down Expand Up @@ -184,7 +184,7 @@ def stop(self):
if not self.thread.is_alive():
return
self.io_loop.call_soon_threadsafe(self.io_loop.stop)
self.thread.join()
# self.thread.join()
# close *all* event pipes, created in any thread
# event pipes can only be used from other threads while self.thread.is_alive()
# so after thread.join, this should be safe
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from IPython.core import release
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
from traitlets import Any, Bool, Instance, List, Type, observe, observe_compat
from zmq.eventloop.zmqstream import ZMQStream

from .comm import CommManager
from .compiler import XCachingCompiler
Expand All @@ -20,6 +19,7 @@
from .kernelbase import Kernel as KernelBase
from .kernelbase import _accepts_cell_id
from .zmqshell import ZMQInteractiveShell
from .zmqstream import ZMQStream

try:
from IPython.core.interactiveshell import _asyncio_runner
Expand Down
1 change: 0 additions & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
)
from traitlets.utils import filefind
from traitlets.utils.importstring import import_item
from zmq.eventloop.zmqstream import ZMQStream

from .control import ControlThread
from .heartbeat import Heartbeat
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _update_eventloop(self, change):
"""schedule call to eventloop from IOLoop"""
loop = asyncio.get_event_loop()
if change.new is not None:
loop.call_soon(self.enter_eventloop())
loop.call_soon(self.enter_eventloop)

session = Instance(Session, allow_none=True)
profile_dir = Instance("IPython.core.profiledir.ProfileDir", allow_none=True)
Expand Down
6 changes: 5 additions & 1 deletion ipykernel/zmqstream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from inspect import isawaitable


class ZMQStream:
Expand All @@ -21,7 +22,10 @@ def on_recv(self, callback, copy=True):

async def recv_task(self, callback, copy):
while True:
msg_list = await self.socket.recv_multipart(copy=copy)
msg_list = self.socket.recv_multipart(copy=copy)
if isawaitable(msg_list):
# in-process kernels are not async
msg_list = await msg_list
callback(msg_list)

def send_multipart(self, msg_list, flags=0, copy=True, track=False, **kwargs):
Expand Down

0 comments on commit 4e5b833

Please sign in to comment.