From a4b990dbf387913cd1afa1eb2bd027c787c9fa35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Fri, 8 Oct 2021 10:23:55 +0200 Subject: [PATCH] Await result of execute_request 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. --- jupyter_ui_poll/_poll.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jupyter_ui_poll/_poll.py b/jupyter_ui_poll/_poll.py index 81fb11e..5fb431d 100644 --- a/jupyter_ui_poll/_poll.py +++ b/jupyter_ui_poll/_poll.py @@ -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, @@ -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 @@ -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