Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native coroutines instead of tornado coroutines #632

Merged
merged 3 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# Imports
#-----------------------------------------------------------------------------

import asyncio

# IPython imports
from traitlets import Type, Instance, default
from jupyter_client.clientabc import KernelClientABC
Expand Down Expand Up @@ -173,8 +175,8 @@ def _dispatch_to_kernel(self, msg):
stream = kernel.shell_stream
self.session.send(stream, msg)
msg_parts = stream.recv_multipart()
kernel.dispatch_shell(msg_parts)

loop = asyncio.get_event_loop()
loop.run_until_complete(kernel.dispatch_shell(msg_parts))
idents, reply_msg = self.session.recv(stream, copy=False)
self.shell_channel.call_handlers_later(reply_msg)

Expand Down
6 changes: 3 additions & 3 deletions ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ def __init__(self, **traits):
self._underlying_iopub_socket.observe(self._io_dispatch, names=['message_sent'])
self.shell.kernel = self

def execute_request(self, stream, ident, parent):
async def execute_request(self, stream, ident, parent):
""" Override for temporary IO redirection. """
with self._redirected_io():
super(InProcessKernel, self).execute_request(stream, ident, parent)
await super(InProcessKernel, self).execute_request(stream, ident, parent)

def start(self):
""" Override registration of dispatchers for streams. """
self.shell.exit_now = False

def _abort_queues(self):
async def _abort_queues(self):
""" The in-process kernel doesn't abort requests. """
pass

Expand Down
21 changes: 7 additions & 14 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from IPython.core import release
from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
from tornado import gen
from traitlets import Instance, Type, Any, List, Bool, observe, observe_compat
from zmq.eventloop.zmqstream import ZMQStream

Expand Down Expand Up @@ -149,8 +148,7 @@ def __init__(self, **kwargs):
'file_extension': '.py'
}

@gen.coroutine
def dispatch_debugpy(self, msg):
async def dispatch_debugpy(self, msg):
# The first frame is the socket id, we can drop it
frame = msg[1].bytes.decode('utf-8')
self.log.debug("Debugpy received: %s", frame)
Expand Down Expand Up @@ -279,9 +277,8 @@ def set_sigint_result():
# restore the previous sigint handler
signal.signal(signal.SIGINT, save_sigint)

@gen.coroutine
def do_execute(self, code, silent, store_history=True,
user_expressions=None, allow_stdin=False):
async def do_execute(self, code, silent, store_history=True,
user_expressions=None, allow_stdin=False):
shell = self.shell # we'll need this a lot here

self._forward_input(allow_stdin)
Expand All @@ -294,8 +291,7 @@ def do_execute(self, code, silent, store_history=True,
should_run_async = lambda cell: False
# older IPython,
# use blocking run_cell and wrap it in coroutine
@gen.coroutine
def run_cell(*args, **kwargs):
async def run_cell(*args, **kwargs):
return shell.run_cell(*args, **kwargs)
try:

Expand Down Expand Up @@ -327,7 +323,7 @@ def run_cell(*args, **kwargs):
with self._cancel_on_sigint(coro_future):
res = None
try:
res = yield coro_future
res = await coro_future
finally:
shell.events.trigger('post_execute')
if not silent:
Expand Down Expand Up @@ -407,9 +403,8 @@ def do_complete(self, code, cursor_pos):
'metadata' : {},
'status' : 'ok'}

@gen.coroutine
def do_debug_request(self, msg):
return (yield self.debugger.process_request(msg))
async def do_debug_request(self, msg):
return await self.debugger.process_request(msg)

def _experimental_do_complete(self, code, cursor_pos):
"""
Expand Down Expand Up @@ -445,8 +440,6 @@ def _experimental_do_complete(self, code, cursor_pos):
'metadata': {_EXPERIMENTAL_KEY_NAME: comps},
'status': 'ok'}



def do_inspect(self, code, cursor_pos, detail_level=0):
name = token_at_cursor(code, cursor_pos)

Expand Down
Loading