echod.py 621 B

123456789101112131415161718192021222324252627282930
  1. # coding: utf-8
  2. import sys
  3. import asyncio
  4. import logging
  5. from echo import api
  6. log = logging.getLogger('echo')
  7. log.addHandler(logging.StreamHandler(sys.stdout))
  8. log.setLevel(logging.DEBUG)
  9. if __name__ == '__main__':
  10. loop = asyncio.get_event_loop()
  11. tcp_port = 8080
  12. server, handler, redis_pool = loop.run_until_complete(
  13. api.start(loop, tcp_port))
  14. try:
  15. loop.run_forever()
  16. except KeyboardInterrupt:
  17. pass
  18. finally:
  19. loop.run_until_complete(handler.finish_connections(1.0))
  20. loop.run_until_complete(redis_pool.clear())
  21. api.stop(loop)
  22. loop.close()