From be0f3731b430bab7efdee4167d60ee30acc237fa Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 12 Jul 2017 22:26:58 +0900 Subject: [PATCH] ensure loop.close() and sys.exit() in gunicorn worker --- sanic/worker.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sanic/worker.py b/sanic/worker.py index 7c02053c..9f950c34 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -3,6 +3,7 @@ import sys import signal import asyncio import logging +import traceback try: import ssl @@ -69,10 +70,16 @@ class GunicornWorker(base.Worker): trigger_events(self._server_settings.get('before_stop', []), self.loop) self.loop.run_until_complete(self.close()) + except: + traceback.print_exc() finally: - trigger_events(self._server_settings.get('after_stop', []), - self.loop) - self.loop.close() + try: + trigger_events(self._server_settings.get('after_stop', []), + self.loop) + except: + traceback.print_exc() + finally: + self.loop.close() sys.exit(self.exit_code)