Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save normanlmfung/a5f85dcf0c6a12ca8a7599d92ce3d9a7 to your computer and use it in GitHub Desktop.
Save normanlmfung/a5f85dcf0c6a12ca8a7599d92ce3d9a7 to your computer and use it in GitHub Desktop.
python_syntax_asyncio_run_in_executor
import asyncio
import concurrent.futures
def sync_function():
return "Hello from a synchronous function!"
async def main():
with concurrent.futures.ThreadPoolExecutor() as executor:
result = await asyncio.get_running_loop().run_in_executor(executor, sync_function)
print(result)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment