Merge pull request #65 from blakev/feature/expose-loop
Exposes `loop`in sanic `serve` and `run` functions (#64)
This commit is contained in:
commit
2903e7ee7c
@ -169,7 +169,7 @@ class Sanic:
|
|||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
|
|
||||||
def run(self, host="127.0.0.1", port=8000, debug=False, after_start=None,
|
def run(self, host="127.0.0.1", port=8000, debug=False, after_start=None,
|
||||||
before_stop=None, sock=None, workers=1):
|
before_stop=None, sock=None, workers=1, loop=None):
|
||||||
"""
|
"""
|
||||||
Runs the HTTP Server and listens until keyboard interrupt or term
|
Runs the HTTP Server and listens until keyboard interrupt or term
|
||||||
signal. On termination, drains connections before closing.
|
signal. On termination, drains connections before closing.
|
||||||
@ -183,6 +183,7 @@ class Sanic:
|
|||||||
:param sock: Socket for the server to accept connections from
|
:param sock: Socket for the server to accept connections from
|
||||||
:param workers: Number of processes
|
:param workers: Number of processes
|
||||||
received before it is respected
|
received before it is respected
|
||||||
|
:param loop: asyncio compatible event loop
|
||||||
:return: Nothing
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
self.error_handler.debug = True
|
self.error_handler.debug = True
|
||||||
@ -196,6 +197,7 @@ class Sanic:
|
|||||||
'request_handler': self.handle_request,
|
'request_handler': self.handle_request,
|
||||||
'request_timeout': self.config.REQUEST_TIMEOUT,
|
'request_timeout': self.config.REQUEST_TIMEOUT,
|
||||||
'request_max_size': self.config.REQUEST_MAX_SIZE,
|
'request_max_size': self.config.REQUEST_MAX_SIZE,
|
||||||
|
'loop': loop
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -159,13 +159,29 @@ class HttpProtocol(asyncio.Protocol):
|
|||||||
|
|
||||||
def serve(host, port, request_handler, after_start=None, before_stop=None,
|
def serve(host, port, request_handler, after_start=None, before_stop=None,
|
||||||
debug=False, request_timeout=60, sock=None,
|
debug=False, request_timeout=60, sock=None,
|
||||||
request_max_size=None, reuse_port=False):
|
request_max_size=None, reuse_port=False, loop=None):
|
||||||
# Create Event Loop
|
"""
|
||||||
loop = async_loop.new_event_loop()
|
Starts asynchronous HTTP Server on an individual process.
|
||||||
|
:param host: Address to host on
|
||||||
|
:param port: Port to host on
|
||||||
|
:param request_handler: Sanic request handler with middleware
|
||||||
|
:param after_start: Function to be executed after the server starts
|
||||||
|
listening. Takes single argument `loop`
|
||||||
|
:param before_stop: Function to be executed when a stop signal is
|
||||||
|
received before it is respected. Takes single argumenet `loop`
|
||||||
|
:param debug: Enables debug output (slows server)
|
||||||
|
:param request_timeout: time in seconds
|
||||||
|
:param sock: Socket for the server to accept connections from
|
||||||
|
:param request_max_size: size in bytes, `None` for no limit
|
||||||
|
:param reuse_port: `True` for multiple workers
|
||||||
|
:param loop: asyncio compatible event loop
|
||||||
|
:return: Nothing
|
||||||
|
"""
|
||||||
|
loop = loop or async_loop.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
# I don't think we take advantage of this
|
|
||||||
# And it slows everything waaayyy down
|
if debug:
|
||||||
# loop.set_debug(debug)
|
loop.set_debug(debug)
|
||||||
|
|
||||||
connections = {}
|
connections = {}
|
||||||
signal = Signal()
|
signal = Signal()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user