From dc9f4e89e672b2ed228ecaa2655a6d5e75eb89ea Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 29 Jul 2019 22:49:30 +0100 Subject: [PATCH] ansible: reap mux processes on shut down Previously we exitted without calling waitpid(), which meant the top-level process struct rusage did not reflect the resource usage consumed by the multiplexer processes. Existing benchmarks are made using perf so this never created a problem, but it could be confusing to others using the "time" command, and also allows logging the final exit status of the process. --- ansible_mitogen/process.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/process.py b/ansible_mitogen/process.py index cb130abc..7cdd68ae 100644 --- a/ansible_mitogen/process.py +++ b/ansible_mitogen/process.py @@ -407,6 +407,12 @@ class ClassicWorkerModel(WorkerModel): mitogen.core.io_op(sock.recv, 1) sock.close() + for mux in self._muxes: + _, status = os.waitpid(mux.pid, 0) + status = mitogen.fork._convert_exit_status(status) + LOG.debug('mux %d PID %d %s', mux.index, mux.pid, + mitogen.parent.returncode_to_str(status)) + def _initialize(self): """ Arrange for classic process model connection multiplexer child @@ -555,7 +561,6 @@ class MuxProcess(object): mitogen.core.io_op(MuxProcess.cls_parent_sock.recv, 1) return - save_pid('mux') ansible_mitogen.logging.set_process_name('mux:' + str(self.index)) if setproctitle: setproctitle.setproctitle('mitogen mux:%s (%s)' % (