Created
March 30, 2024 23:07
-
-
Save normanlmfung/a5f85dcf0c6a12ca8a7599d92ce3d9a7 to your computer and use it in GitHub Desktop.
python_syntax_asyncio_run_in_executor
This file contains hidden or 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
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