Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # encoding=utf-8
  3. import asyncio
  4. from utility import time_me, hello
  5. from run_ import run, create_task
  6. """
  7. filename: basic18.py
  8. description: call back
  9. License: GPL V2
  10. Author: 天使de眼睛
  11.  
  12. 除特别声明,所有代码均是 python3.6 在 iOS 环境下编写测试。
  13. """
  14.  
  15. asyncio.run = run
  16. asyncio.create_task = create_task
  17.  
  18. def call_back(task):
  19. print('in callback:', task.result())
  20.  
  21. @time_me
  22. async def main():
  23. tasks = [asyncio.create_task(hello(1, 'Kitty')), asyncio.create_task(hello(2, 'Doggy')) ]
  24. for task in tasks:
  25. task.add_done_callback(call_back)
  26. await task
  27.  
  28.  
  29. if __name__ == '__main__':
  30. asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement