Created
March 21, 2025 16:43
-
-
Save sefgit/8378d840c249028729c5c652d1eb36ed to your computer and use it in GitHub Desktop.
asyncio thread
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
# https://daily.dev/blog/get-to-know-asynchio-multithreaded-python-using-asyncawait | |
import asyncio | |
import threading | |
async def main(): | |
result = await asyncio.to_thread(blocking_func) | |
print(result) | |
asyncio.run(main()) |
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
fut = asyncio.run_coroutine_threadsafe(coro_func(), loop) | |
result = fut.result() | |
# https://daily.dev/blog/get-to-know-asynchio-multithreaded-python-using-asyncawait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment