Skip to content

Instantly share code, notes, and snippets.

@grimen
Created January 29, 2022 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grimen/42228d06992d226079804fc9a891aa03 to your computer and use it in GitHub Desktop.
Save grimen/42228d06992d226079804fc9a891aa03 to your computer and use it in GitHub Desktop.
# @source: https://medium.com/@DorIndivo/how-we-migrated-from-python-multithreading-to-asyncio-128b0c8e4ec5
async def run_func_async(func:Callable, func_args:List[Any], executor:ThreadPoolExecutor):
if asyncio.iscoroutinefunction(func):
return await func(*func_args)
else:
return await asyncio.get_event_loop().run_in_executor(
func=lambda:func(*func_args), executor=executor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment