fixbug: async Editor.read

This commit is contained in:
莘权 马 2024-08-09 17:47:35 +08:00
parent 06f8ee05cb
commit d900a01844
3 changed files with 12 additions and 38 deletions

View file

@ -12,7 +12,6 @@
from __future__ import annotations
import ast
import asyncio
import base64
import contextlib
import csv
@ -1054,32 +1053,6 @@ def tool2name(cls, methods: List[str], entry) -> Dict[str, Any]:
return mappings
def run_coroutine_sync(coroutine, *args, **kwargs):
"""
Runs a coroutine function synchronously by encapsulating its invocation as a non-coroutine function call.
Args:
coroutine: The coroutine function to be encapsulated.
*args: Positional arguments to be passed to the coroutine.
**kwargs: Keyword arguments to be passed to the coroutine.
Returns:
The return value of the coroutine.
"""
try:
loop = asyncio.get_running_loop()
except RuntimeError: # No running event loop
loop = None
if loop and loop.is_running():
# The event loop is already running
future = asyncio.run_coroutine_threadsafe(coroutine(*args, **kwargs), loop)
return future.result()
else:
# The event loop is not running
return asyncio.run(coroutine(*args, **kwargs))
def log_time(method):
"""A time-consuming decorator for printing execution duration."""