可乐博客

Python 异步编程之asyncio和Tornado

有空写
create_task run_until_complete ensure_future

# -*- coding: utf-8 -*-
"""回声服务"""
# import sys
# from typing import Tuple
# from types import FrameType
# from logging import getLogger
from asyncio import get_event_loop
# from signal import signal, SIGINT, SIGTERM

# from tornado.tcpserver import TCPServer
# from tornado.netutil import bind_sockets
# from tornado.options import define, options
# from tornado.iostream import IOStream, StreamClosedError

import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    async def get(self):
        self.write("Hello, world")


application = tornado.web.Application([
    (r"/index", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    # tornado.ioloop.IOLoop.instance().start()
    loop = get_event_loop()
    loop.run_forever()
Pythonic,随笔