Merge pull request #171 from jpiasetz/convert_dict_to_set

Convert connections dict to set
This commit is contained in:
Eli Uriegas 2016-12-14 11:30:45 -06:00 committed by GitHub
commit 35e79f3985

View File

@ -60,14 +60,14 @@ class HttpProtocol(asyncio.Protocol):
# -------------------------------------------- # # -------------------------------------------- #
def connection_made(self, transport): def connection_made(self, transport):
self.connections[self] = True self.connections.add(self)
self._timeout_handler = self.loop.call_later( self._timeout_handler = self.loop.call_later(
self.request_timeout, self.connection_timeout) self.request_timeout, self.connection_timeout)
self.transport = transport self.transport = transport
self._last_request_time = current_time self._last_request_time = current_time
def connection_lost(self, exc): def connection_lost(self, exc):
del self.connections[self] self.connections.discard(self)
self._timeout_handler.cancel() self._timeout_handler.cancel()
self.cleanup() self.cleanup()
@ -250,7 +250,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
trigger_events(before_start, loop) trigger_events(before_start, loop)
connections = {} connections = set()
signal = Signal() signal = Signal()
server = partial( server = partial(
HttpProtocol, HttpProtocol,
@ -301,7 +301,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
# Complete all tasks on the loop # Complete all tasks on the loop
signal.stopped = True signal.stopped = True
for connection in connections.keys(): for connection in connections:
connection.close_if_idle() connection.close_if_idle()
while connections: while connections: