Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created February 23, 2017 21:30
Show Gist options
  • Select an option

  • Save nenodias/d3a234a8357b589764d7160662f14488 to your computer and use it in GitHub Desktop.

Select an option

Save nenodias/d3a234a8357b589764d7160662f14488 to your computer and use it in GitHub Desktop.
Async IO
import asyncio
from time import time
def run_async():
startT = time()
async def speak_async():
print("With Async :)")
loop = asyncio.get_event_loop()
loop.run_until_complete(speak_async())
loop.close()
print(time() - startT)
def run_sync():
startT = time()
def speak():
print("Withou Async :(")
speak()
print(time() - startT)
if __name__ == '__main__':
valor = None
while valor != '1' and valor != '2':
valor = input('Executar: (1 - Async | 2 - Sync)')
if valor == '1':
run_async()
elif valor == '2':
run_sync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment