Call async function from sync function, while the synchronous function continues : Python

Just use asyncio.run() inside a synchronous function.

def syncfunc():
    async def asyncfunc():
        await some_async_work()
    asyncio.run(asyncfunc())

syncfunc()

Note that asyncio.run() cannot be called when another asyncio event loop is running in the same thread.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)