Skip to content

Commit

Permalink
Await result of execute_request
Browse files Browse the repository at this point in the history
Fixes #16.

In some cases ipykernel 5 returns an awaitable when executing a request.
We need to await it to get the correct order of execution of async cells.
  • Loading branch information
saraedum authored and Kirill888 committed Oct 8, 2021
1 parent ce4e3d4 commit a4b990d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions jupyter_ui_poll/_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from collections import abc
from functools import singledispatch
from inspect import iscoroutinefunction
from inspect import iscoroutinefunction, isawaitable
from typing import (
Any,
AsyncIterable,
Expand Down Expand Up @@ -46,9 +46,8 @@ def __init__(self, shell, loop) -> None:
self._events: List[Tuple[Any, Any, Any]] = []
self._backup_execute_request = kernel.shell_handlers["execute_request"]
self._aproc = None
self._kernel_is_async = iscoroutinefunction(self._backup_execute_request)

if self._kernel_is_async: # ipykernel 6+
if iscoroutinefunction(self._backup_execute_request): # ipykernel 6+
kernel.shell_handlers["execute_request"] = self._execute_request_async
else:
# ipykernel < 6
Expand Down Expand Up @@ -90,7 +89,7 @@ async def replay(self):
kernel._send_abort_reply(stream, parent, ident)
else:
rr = kernel.execute_request(stream, ident, parent)
if self._kernel_is_async:
if isawaitable(rr):
await rr

# replicate shell_dispatch behaviour
Expand Down

0 comments on commit a4b990d

Please sign in to comment.