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

Import ensure_async from jupyter_core #1093

Merged
merged 5 commits into from
Nov 29, 2022
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
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