From 05d0ddc2816890b8b5b13eb2887622656cbb9790 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 00:01:51 +0800 Subject: [PATCH] Gunicorn worker should not require uvloop --- sanic/worker.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sanic/worker.py b/sanic/worker.py index b2f5af17..30ad91b0 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -9,7 +9,11 @@ try: except ImportError: ssl = None -import uvloop +try: + import uvloop + asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) +except ImportError: + pass import gunicorn.workers.base as base from sanic.server import trigger_events, serve, HttpProtocol, Signal @@ -34,7 +38,6 @@ class GunicornWorker(base.Worker): # create new event_loop after fork asyncio.get_event_loop().close() - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop)