Skip to content

Commit

Permalink
Import ensure_async from jupyter_core (#1093)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Silvester <[email protected]>
  • Loading branch information
davidbrochart and blink1073 authored Nov 29, 2022
1 parent 96bcdbb commit 5965c7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
19 changes: 1 addition & 18 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5965c7f

Please sign in to comment.