Created
January 29, 2022 11:02
-
-
Save grimen/42228d06992d226079804fc9a891aa03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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