fix async run
This commit is contained in:
parent
ab9a393bdf
commit
abfea2b568
|
@ -297,8 +297,8 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
:param protocol: Subclass of asyncio protocol class
|
:param protocol: Subclass of asyncio protocol class
|
||||||
:return: Nothing
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
loop = async_loop.new_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop_policy(async_loop.EventLoopPolicy())
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
loop.set_debug(debug)
|
loop.set_debug(debug)
|
||||||
|
|
27
tests/test_loop_policy.py
Normal file
27
tests/test_loop_policy.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from sanic import Sanic
|
||||||
|
import asyncio
|
||||||
|
from signal import signal, SIGINT
|
||||||
|
import uvloop
|
||||||
|
|
||||||
|
|
||||||
|
def test_loop_policy():
|
||||||
|
app = Sanic('test_loop_policy')
|
||||||
|
|
||||||
|
server = app.create_server(host="0.0.0.0", port=8000)
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
task = asyncio.ensure_future(server)
|
||||||
|
signal(SIGINT, lambda s, f: loop.close())
|
||||||
|
|
||||||
|
# serve() sets the event loop policy to uvloop but
|
||||||
|
# doesn't get called until we run the server task
|
||||||
|
assert isinstance(asyncio.get_event_loop_policy(),
|
||||||
|
asyncio.unix_events._UnixDefaultEventLoopPolicy)
|
||||||
|
|
||||||
|
try:
|
||||||
|
loop.run_until_complete(task)
|
||||||
|
except:
|
||||||
|
loop.stop()
|
||||||
|
|
||||||
|
assert isinstance(asyncio.get_event_loop_policy(),
|
||||||
|
uvloop.EventLoopPolicy)
|
Loading…
Reference in New Issue
Block a user