Skip to content

Commit 1fb882e

Browse files
committed
fix(runtime): guard sync API when called from async context (closes #1085)
1 parent 28ffc32 commit 1fb882e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/cocoindex/runtime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import inspect
99
import warnings
1010

11-
from typing import Any, Callable, Awaitable, TypeVar
11+
from typing import Any, Callable, Awaitable, TypeVar, Coroutine
1212

1313
T = TypeVar("T")
1414

@@ -35,7 +35,7 @@ def _runner(l: asyncio.AbstractEventLoop) -> None:
3535
threading.Thread(target=_runner, args=(loop,), daemon=True).start()
3636
return self._event_loop
3737

38-
def run(self, coro):
38+
def run(self, coro: Coroutine[Any, Any, T]) -> T:
3939
"""Run a coroutine in the event loop, blocking until it finishes. Return its result."""
4040
try:
4141
running_loop = asyncio.get_running_loop()
@@ -69,4 +69,4 @@ def run(self, coro):
6969
def to_async_call(call: Callable[..., Any]) -> Callable[..., Awaitable[Any]]:
7070
if inspect.iscoroutinefunction(call):
7171
return call
72-
return lambda *args, **kwargs: asyncio.to_thread(lambda: call(*args, **kwargs))
72+
return lambda *args, **kwargs: asyncio.to_thread(lambda: call(*args, **kwargs))

0 commit comments

Comments
 (0)