Skip to content

Commit 7ff8135

Browse files
committed
Import ensure_async from jupyter_core
1 parent e9735fc commit 7ff8135

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

jupyter_server/utils.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from urllib.request import pathname2url # noqa: F401
1515

1616
from _frozen_importlib_external import _NamespacePath
17+
from jupyter_core.utils import ensure_async # noqa: F401
1718
from packaging.version import Version
1819
from tornado.httpclient import AsyncHTTPClient, HTTPClient, HTTPRequest
1920
from tornado.netutil import Resolver
@@ -173,23 +174,6 @@ def _check_pid_posix(pid):
173174
check_pid = _check_pid_posix
174175

175176

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-
193177
async def run_sync_in_loop(maybe_async):
194178
"""**DEPRECATED**: Use ``ensure_async`` instead."""
195179
warnings.warn(

0 commit comments

Comments
 (0)