Clear tornado ioloop before os.fork (#1831)

This commit is contained in:
7 2018-07-21 13:38:04 -07:00 committed by Randall Leeds
parent 7d0787cd1a
commit cdd147841a

View File

@ -69,6 +69,14 @@ class TornadoWorker(Worker):
if not self.ioloop._callbacks:
self.ioloop.stop()
def init_process(self):
# IOLoop cannot survive a fork or be shared across processes
# in any way. When multiple processes are being used, each process
# should create its own IOLoop. We should clear current IOLoop
# if exists before os.fork.
IOLoop.clear_current()
super(TornadoWorker, self).init_process()
def run(self):
self.ioloop = IOLoop.instance()
self.alive = True