diff --git a/sanic/server.py b/sanic/server.py index be9bc31c..48c3827e 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -297,8 +297,8 @@ def serve(host, port, request_handler, error_handler, before_start=None, :param protocol: Subclass of asyncio protocol class :return: Nothing """ - loop = asyncio.get_event_loop() - asyncio.set_event_loop_policy(async_loop.EventLoopPolicy()) + loop = async_loop.new_event_loop() + asyncio.set_event_loop(loop) if debug: loop.set_debug(debug) diff --git a/tests/test_loop_policy.py b/tests/test_loop_policy.py deleted file mode 100644 index f764548c..00000000 --- a/tests/test_loop_policy.py +++ /dev/null @@ -1,27 +0,0 @@ -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)