From: shanghui Date: Wed, 6 Dec 2017 06:45:21 +0000 (+0800) Subject: Make the example code in the document "tornado.ioloop — Main event loop" can copy... X-Git-Tag: v5.0.0~37^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f599293da43720b6cc20f3770a7a62d0a8ee5ea;p=thirdparty%2Ftornado.git Make the example code in the document "tornado.ioloop — Main event loop" can copy-paste-run directly. --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index c950a89d3..ea9261294 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -89,9 +89,18 @@ class IOLoop(Configurable): import errno import functools - import tornado.ioloop import socket + import tornado.ioloop + from tornado import gen + from tornado.iostream import IOStream + + @gen.coroutine + def handle_connection(connection, address): + stream = IOStream(connection) + message = yield stream.read_until_close() + print("message from client:", message.decode().strip()) + def connection_ready(sock, fd, events): while True: try: @@ -107,7 +116,7 @@ class IOLoop(Configurable): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setblocking(0) - sock.bind(("", port)) + sock.bind(("", 8888)) sock.listen(128) io_loop = tornado.ioloop.IOLoop.current()