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

add headers openai #1357

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 36 additions & 3 deletions src/evidently/utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,46 @@

def async_to_sync(awaitable: Awaitable[TA]) -> TA:
try:
asyncio.get_running_loop()
loop = asyncio.get_running_loop()
# we are in sync context but inside a running loop
print(
f"loop {loop}",
)
if not _thr.is_alive():
_thr.start()
print("start loop", loop)
# _thr.start()
future = asyncio.run_coroutine_threadsafe(awaitable, _loop)
return future.result()
except RuntimeError:
except RuntimeError as e:
print("RuntimeError", e)
print("creating new loop")
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
try:
return new_loop.run_until_complete(awaitable)
finally:
new_loop.close()

# def async_to_sync(awaitable: Awaitable[TA]) -> TA:
# try:
# loop = asyncio.get_running_loop()
# # we are in sync context but inside a running loop
# print("loop", loop)
#
# if not loop.is_running():
# print("loop is not running", loop)
# new_loop = asyncio.new_event_loop()
# asyncio.set_event_loop(new_loop)
# try:
# return new_loop.run_until_complete(awaitable)
# finally:
# new_loop.close()
#
# future = asyncio.run_coroutine_threadsafe(awaitable, _loop)
# return future.result()

except RuntimeError as e:
print("RuntimeError, creating new_event_loop", e)
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
try:
Expand Down
Loading