ansible: ensure MuxProcess MITOGEN_PROFILING results reach disk.

This has been broken for quite some time.
pull/564/head
David Wilson 6 years ago
parent 2209d880e4
commit 84944a9a61

@ -163,7 +163,8 @@ class MuxProcess(object):
mitogen.core.set_cloexec(cls.worker_sock.fileno()) mitogen.core.set_cloexec(cls.worker_sock.fileno())
mitogen.core.set_cloexec(cls.child_sock.fileno()) mitogen.core.set_cloexec(cls.child_sock.fileno())
if os.environ.get('MITOGEN_PROFILING'): cls.profiling = os.environ.get('MITOGEN_PROFILING') is not None
if cls.profiling:
mitogen.core.enable_profiling() mitogen.core.enable_profiling()
cls.original_env = dict(os.environ) cls.original_env = dict(os.environ)
@ -281,7 +282,9 @@ class MuxProcess(object):
then cannot clean up pending handlers, which is required for the then cannot clean up pending handlers, which is required for the
threads to exit gracefully. threads to exit gracefully.
""" """
self.pool.stop(join=False) # In normal operation we presently kill the process because there is
# not yet any way to cancel connect().
self.pool.stop(join=self.profiling)
def on_broker_exit(self): def on_broker_exit(self):
""" """
@ -289,10 +292,9 @@ class MuxProcess(object):
ourself. In future this should gracefully join the pool, but TERM is ourself. In future this should gracefully join the pool, but TERM is
fine for now. fine for now.
""" """
if os.environ.get('MITOGEN_PROFILING'): if not self.profiling:
# TODO: avoid killing pool threads before they have written their # In normal operation we presently kill the process because there is
# .pstats. Really shouldn't be using kill() here at all, but hard # not yet any way to cancel connect(). When profiling, threads
# to guarantee services can always be unblocked during shutdown. # including the broker must shut down gracefully, otherwise pstats
time.sleep(1) # won't be written.
os.kill(os.getpid(), signal.SIGTERM)
os.kill(os.getpid(), signal.SIGTERM)

Loading…
Cancel
Save