Skip to content

Instantly share code, notes, and snippets.

@barrachri
Last active October 29, 2018 03:08
Show Gist options
  • Save barrachri/80b20f239567b2032606835bdaae849d to your computer and use it in GitHub Desktop.
Save barrachri/80b20f239567b2032606835bdaae849d to your computer and use it in GitHub Desktop.
"""Needs Python 3.7"""
import asyncio
import time
def blocking():
print("\tStarting sleeping")
time.sleep(5)
print("\tSleeping completed")
return "Hello World"
async def hello_world():
print("Waiting for blocking")
loop = asyncio.get_running_loop()
future = loop.run_in_executor(None, blocking)
print("I don't want to wait")
result = await future
print(result)
asyncio.run(hello_world())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment