serve closes the loop only when it created its own loop.
When you were running multiple applications using asyncio, sanic must be closed as the latest order because it closes the loop. The patch limits the behavior only when sanic created its own loop by argument `loop=None`.
This commit is contained in:
@@ -290,7 +290,9 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||
:param protocol: Subclass of asyncio protocol class
|
||||
:return: Nothing
|
||||
"""
|
||||
loop = loop or async_loop.new_event_loop()
|
||||
create_new_loop = loop is None
|
||||
if create_new_loop:
|
||||
loop = async_loop.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
if debug:
|
||||
@@ -360,4 +362,5 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||
|
||||
trigger_events(after_stop, loop)
|
||||
|
||||
if create_new_loop:
|
||||
loop.close()
|
||||
|
||||
Reference in New Issue
Block a user