In debug mode, BaseEventLoop._run_once() now sets the BaseEventLoop._current_handle attribute to the handle currently executed. In release mode or when no handle is executed, the attribute is None. BaseEventLoop.default_exception_handler() displays the traceback of the current handle if available.
21 lines
439 B
Python
21 lines
439 B
Python
import asyncio
|
|
|
|
@asyncio.coroutine
|
|
def echo_server():
|
|
yield from asyncio.start_server(handle_connection, 'localhost', 8000)
|
|
|
|
@asyncio.coroutine
|
|
def handle_connection(reader, writer):
|
|
while True:
|
|
data = yield from reader.read(8192)
|
|
if not data:
|
|
break
|
|
writer.write(data)
|
|
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(echo_server())
|
|
try:
|
|
loop.run_forever()
|
|
finally:
|
|
loop.close()
|