Skip to content

Commit 5965c7f

Browse files
Import ensure_async from jupyter_core (#1093)
Co-authored-by: Steven Silvester <[email protected]>
1 parent 96bcdbb commit 5965c7f

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

jupyter_server/utils.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Distributed under the terms of the Modified BSD License.
44
import errno
55
import importlib.util
6-
import inspect
76
import os
87
import socket
98
import sys
@@ -14,6 +13,7 @@
1413
from urllib.request import pathname2url # noqa: F401
1514

1615
from _frozen_importlib_external import _NamespacePath
16+
from jupyter_core.utils import ensure_async # noqa: F401
1717
from packaging.version import Version
1818
from tornado.httpclient import AsyncHTTPClient, HTTPClient, HTTPRequest
1919
from tornado.netutil import Resolver
@@ -173,23 +173,6 @@ def _check_pid_posix(pid):
173173
check_pid = _check_pid_posix
174174

175175

176-
async def ensure_async(obj):
177-
"""Convert a non-awaitable object to a coroutine if needed,
178-
and await it if it was not already awaited.
179-
"""
180-
if inspect.isawaitable(obj):
181-
try:
182-
result = await obj
183-
except RuntimeError as e:
184-
if str(e) == "cannot reuse already awaited coroutine":
185-
# obj is already the coroutine's result
186-
return obj
187-
raise
188-
return result
189-
# obj doesn't need to be awaited
190-
return obj
191-
192-
193176
async def run_sync_in_loop(maybe_async):
194177
"""**DEPRECATED**: Use ``ensure_async`` instead."""
195178
warnings.warn(

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"argon2-cffi",
3232
"jinja2",
3333
"jupyter_client>=7.4.4",
34-
"jupyter_core>=4.9.2",
34+
"jupyter_core>=4.12,!=~5.0",
3535
"jupyter_server_terminals",
3636
"nbconvert>=6.4.4",
3737
"nbformat>=5.3.0",

0 commit comments

Comments
 (0)