Fix before_stop event

This commit is contained in:
messense 2017-03-20 14:27:02 +08:00
parent d1fb5bdc30
commit 1396ca903d
No known key found for this signature in database
GPG Key ID: BB41A8A2C716CCA9

View File

@ -64,6 +64,9 @@ class GunicornWorker(base.Worker):
trigger_events(self._server_settings.get('after_start', []), trigger_events(self._server_settings.get('after_start', []),
self.loop) self.loop)
self.loop.run_until_complete(self._check_alive()) self.loop.run_until_complete(self._check_alive())
trigger_events(self._server_settings.get('before_stop', []),
self.loop)
self.loop.run_until_complete(self.close())
finally: finally:
trigger_events(self._server_settings.get('after_stop', []), trigger_events(self._server_settings.get('after_stop', []),
self.loop) self.loop)
@ -72,8 +75,6 @@ class GunicornWorker(base.Worker):
sys.exit(self.exit_code) sys.exit(self.exit_code)
async def close(self): async def close(self):
trigger_events(self._server_settings.get('before_stop', []),
self.loop)
if self.servers: if self.servers:
# stop accepting connections # stop accepting connections
self.log.info("Stopping server: %s, connections: %s", self.log.info("Stopping server: %s, connections: %s",
@ -115,8 +116,6 @@ class GunicornWorker(base.Worker):
except (Exception, BaseException, GeneratorExit, KeyboardInterrupt): except (Exception, BaseException, GeneratorExit, KeyboardInterrupt):
pass pass
await self.close()
@staticmethod @staticmethod
def _create_ssl_context(cfg): def _create_ssl_context(cfg):
""" Creates SSLContext instance for usage in asyncio.create_server. """ Creates SSLContext instance for usage in asyncio.create_server.