Open CyberParadise opened 1 year ago
I've also been wondering for a long time about being able to use this asynchronously, because you won't do much synchronously.
I use decorators :
import time
import os
import asyncio
from functools import wraps, partial
def async_wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run
@async_wrap
def my_async_sleep(duration):
time.sleep(duration)
Hi, is it possible to use it asynchronously?