async def func1():
print(f'{datetime.now().time()} func1 start')
await asyncio.sleep(1)
print(f'{datetime.now().time()} func1 over')
async def func21():
print(f'{datetime.now().time()} func21 start')
await asyncio.sleep(1)
print(f'{datetime.now().time()} func21 over')
def func2():
print(f'{datetime.now().time()} func2 start')
time.sleep(1)
asyncio.run_coroutine_threadsafe(func21(), asyncio.get_event_loop())
print(f'{datetime.now().time()} func2 over')
if __name__ == '__main__':
for i in range(3):
func2()
asyncio.run(func1())
As seen, I want to call async func21() in sync func2(), but it produces RuntimeError when running.
So is it possible to do call async func21() in sync func2()
?If yes, so how would that be?