Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # encoding=utf-8
  3. import asyncio
  4. from utility import hello, time_me, StdErrRedirect
  5. from run_ import run, create_task
  6. """
  7. filename: basic9.py
  8. description: gather with exception
  9. if return_exeptions is set to False, stack will still display. (use StdErrRedirect)
  10. License: GPL V2
  11. Author: 天使de眼睛
  12.  
  13. 除特别声明,所有代码均是 python3.6 在 iOS 环境下编写测试。
  14. """
  15.  
  16. asyncio.run = run
  17. asyncio.create_task = create_task
  18.  
  19. async def gather_tasks():
  20. return await asyncio.gather(hello(2, 'Kitty', raise_exception=True), hello(1, 'Doggy'))
  21.  
  22. @time_me
  23. def main():
  24. try:
  25. with StdErrRedirect():
  26. result = asyncio.run(gather_tasks())
  27. except ValueError as e:
  28. print("Kitty has exception:", e)
  29.  
  30.  
  31. if __name__ == '__main__':
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement