Add finalizer
This commit is contained in:
parent
a77702c799
commit
aed49a99ab
17
demo/main.py
17
demo/main.py
|
@ -30,17 +30,24 @@ def init(loop):
|
||||||
handler = app.make_handler()
|
handler = app.make_handler()
|
||||||
srv = yield from loop.create_server(handler, '127.0.0.1', 8080)
|
srv = yield from loop.create_server(handler, '127.0.0.1', 8080)
|
||||||
print("Server started at http://127.0.0.1:8080")
|
print("Server started at http://127.0.0.1:8080")
|
||||||
return srv, handler
|
return srv, app, handler
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def finalize(loop, srv, handler):
|
def finalize(srv, app, handler):
|
||||||
pass
|
sock = srv.sockets[0]
|
||||||
|
app.loop.remove_reader(sock.fileno())
|
||||||
|
sock.close()
|
||||||
|
|
||||||
|
yield from handler.finish_connections(1.0)
|
||||||
|
srv.close()
|
||||||
|
yield from srv.wait_closed()
|
||||||
|
yield from app.finish()
|
||||||
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
srv, handler = loop.run_until_complete(init(loop))
|
srv, app, handler = loop.run_until_complete(init(loop))
|
||||||
try:
|
try:
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
loop.run_until_complete((finalize(loop)))
|
loop.run_until_complete((finalize(srv, app, handler)))
|
||||||
|
|
Loading…
Reference in New Issue