ansible: insert short sleep when MITOGEN_PROFILING active.

Hacky, but works fine.
pull/350/head
David Wilson 6 years ago
parent d62e6e2a7f
commit 5c573f7fcb

@ -33,6 +33,7 @@ import os
import signal
import socket
import sys
import time
import mitogen
import mitogen.core
@ -114,6 +115,9 @@ class MuxProcess(object):
mitogen.core.set_cloexec(cls.worker_sock.fileno())
mitogen.core.set_cloexec(cls.child_sock.fileno())
if os.environ.get('MITOGEN_PROFILING', '1'):
mitogen.core.enable_profiling()
cls.original_env = dict(os.environ)
cls.child_pid = os.fork()
ansible_mitogen.logging.setup()
@ -199,4 +203,10 @@ class MuxProcess(object):
ourself. In future this should gracefully join the pool, but TERM is
fine for now.
"""
if os.environ.get('MITOGEN_PROFILING'):
# TODO: avoid killing pool threads before they have written their
# .pstats. Really shouldn't be using kill() here at all, but hard
# to guarantee services can always be unblocked during shutdown.
time.sleep(1)
os.kill(os.getpid(), signal.SIGTERM)

@ -350,6 +350,7 @@ def enable_profiling():
try:
return func(*args)
finally:
profiler.dump_stats('/tmp/mitogen.%d.%s.pstat' % (os.getpid(), name))
profiler.create_stats()
fp = open('/tmp/mitogen.stats.%d.%s.log' % (os.getpid(), name), 'w')
try:

Loading…
Cancel
Save