Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. async def uma_funcao():
  2. # algum código preparatório
  3. ...
  4. resultado = await outra_funcao(valores)
  5. # algumas linhas de código usando o resultado acima
  6. ...
  7. return valor
  8.  
  9. import asyncio
  10.  
  11. async def say(what, when):
  12. await asyncio.sleep(when)
  13. print(what)
  14. if when == 5:
  15. loop = asyncio.get_event_loop()
  16. loop.stop()
  17.  
  18. loop = asyncio.new_event_loop()
  19. for i in range(5, -1, -1):
  20. loop.create_task(say(f'hello world {i}', i))
  21. print(f"co-rotina {i} criada")
  22. loop.run_forever()
  23. loop.close()
Add Comment
Please, Sign In to add comment