From: Victor Stinner Date: Tue, 3 Dec 2013 14:04:18 +0000 (+0100) Subject: asyncio doc: simplify ping example, remove the useless timeout X-Git-Tag: v3.4.0b2~362 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=15faa9c8ad1833cea964281e70085a603365a75a;p=thirdparty%2FPython%2Fcpython.git asyncio doc: simplify ping example, remove the useless timeout --- diff --git a/Doc/library/asyncio-protocol.rst b/Doc/library/asyncio-protocol.rst index e3a56568a6f9..5182df5ec34d 100644 --- a/Doc/library/asyncio-protocol.rst +++ b/Doc/library/asyncio-protocol.rst @@ -589,25 +589,21 @@ TCP echo server example:: import asyncio class EchoServer(asyncio.Protocol): - def timeout(self): - print('connection timeout, closing.') - self.transport.close() - def connection_made(self, transport): print('connection made') self.transport = transport - # close the client connection after 2 seconds - asyncio.get_event_loop().call_later(2.0, self.timeout) def data_received(self, data): print('data received:', data.decode()) self.transport.write(data) + # close the socket + self.transport.close() + def connection_lost(self, exc): print('connection lost') - loop = asyncio.get_event_loop() f = loop.create_server(EchoServer, '127.0.0.1', 8888) s = loop.run_until_complete(f)