async_hello.py 381 B

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