PaperParser/app/utils/__init__.py

15 lines
401 B
Python
Raw Normal View History

2024-01-31 19:37:01 +10:00
import asyncio
import functools
def to_sync_task(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_forever()
return loop.run_until_complete(func(*args, **kwargs))
return wrapper