Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sinhlt58/211d0ca1bdf113d9df31437c9aa8f904 to your computer and use it in GitHub Desktop.
Save sinhlt58/211d0ca1bdf113d9df31437c9aa8f904 to your computer and use it in GitHub Desktop.
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