From 13808bf282493fccf81458da129514d5e28e88ac Mon Sep 17 00:00:00 2001 From: John Piasetzki Date: Fri, 25 Nov 2016 14:53:18 -0500 Subject: [PATCH] Convert server lambda to partial Partials are faster then lambdas for repeated calls. --- sanic/server.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index b6233031..edc96968 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -235,14 +235,23 @@ def serve(host, port, request_handler, before_start=None, after_start=None, connections = {} signal = Signal() - server_coroutine = loop.create_server(lambda: HttpProtocol( + server = partial( + HttpProtocol, loop=loop, connections=connections, signal=signal, request_handler=request_handler, request_timeout=request_timeout, request_max_size=request_max_size, - ), host, port, reuse_port=reuse_port, sock=sock) + ) + + server_coroutine = loop.create_server( + server, + host, + port, + reuse_port=reuse_port, + sock=sock + ) # Instead of pulling time at the end of every request, # pull it once per minute