# run_in_executor import asyncio from concurrent.futures import ThreadPoolExecutor
defsync_function(argument1, argument2): pass
asyncdefmain(): loop = asyncio.get_running_loop() with ThreadPoolExecutor() as pool: result = await loop.run_in_executor(pool, sync_function, 'arg1', 'arg2')
1 2 3 4 5 6 7 8 9 10 11 12 13
# run_in_threadpool from fastapi import FastAPI from starlette.concurrency import run_in_threadpool