diff --git a/jupyter_server/utils.py b/jupyter_server/utils.py index 5823321e7a..3a1ebd24d6 100644 --- a/jupyter_server/utils.py +++ b/jupyter_server/utils.py @@ -3,7 +3,6 @@ # Distributed under the terms of the Modified BSD License. import errno import importlib.util -import inspect import os import socket import sys @@ -14,6 +13,7 @@ from urllib.request import pathname2url # noqa: F401 from _frozen_importlib_external import _NamespacePath +from jupyter_core.utils import ensure_async # noqa: F401 from packaging.version import Version from tornado.httpclient import AsyncHTTPClient, HTTPClient, HTTPRequest from tornado.netutil import Resolver @@ -173,23 +173,6 @@ def _check_pid_posix(pid): check_pid = _check_pid_posix -async def ensure_async(obj): - """Convert a non-awaitable object to a coroutine if needed, - and await it if it was not already awaited. - """ - if inspect.isawaitable(obj): - try: - result = await obj - except RuntimeError as e: - if str(e) == "cannot reuse already awaited coroutine": - # obj is already the coroutine's result - return obj - raise - return result - # obj doesn't need to be awaited - return obj - - async def run_sync_in_loop(maybe_async): """**DEPRECATED**: Use ``ensure_async`` instead.""" warnings.warn( diff --git a/pyproject.toml b/pyproject.toml index d350a106b3..93d2c6d2ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dependencies = [ "argon2-cffi", "jinja2", "jupyter_client>=7.4.4", - "jupyter_core>=4.9.2", + "jupyter_core>=4.12,!=~5.0", "jupyter_server_terminals", "nbconvert>=6.4.4", "nbformat>=5.3.0",