Created
July 23, 2019 07:24
-
-
Save sinhlt58/211d0ca1bdf113d9df31437c9aa8f904 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
https://www.aeracode.org/2018/02/19/python-async-simplified/ | |
def get_chat_id(name): | |
# blocking code | |
return Chat.objects.get(name=name).id | |
async def main(): | |
executor = concurrent.futures.ThreadPoolExecutor(max_workers=3) | |
loop = asyncio.get_event_loop() | |
result = await loop.run_in_executor(executor, get_chat_id, "django") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment