async_wget2.py 363 B

123456789101112131415
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import threading
  4. import asyncio
  5. async def hello():
  6. print('Hello world! (%s)' % threading.currentThread())
  7. await asyncio.sleep(1)
  8. print('Hello again! (%s)' % threading.currentThread())
  9. loop = asyncio.get_event_loop()
  10. tasks = [hello(), hello()]
  11. loop.run_until_complete(asyncio.wait(tasks))
  12. loop.close()