Merge "executor: Catch error when reading cpu_times"

This commit is contained in:
Zuul 2020-05-10 17:17:29 +00:00 committed by Gerrit Code Review
commit d873dc84ef
1 changed files with 17 additions and 11 deletions

View File

@ -19,6 +19,7 @@ import json
import logging
import multiprocessing
import os
import psutil
import shutil
import signal
import shlex
@ -2231,17 +2232,22 @@ class AnsibleJob(object):
line = line[:1024].rstrip()
ansible_log.debug("Ansible output: %s" % (line,))
self.log.debug("Ansible output terminated")
cpu_times = self.proc.cpu_times()
self.log.debug("Ansible cpu times: user=%.2f, system=%.2f, "
"children_user=%.2f, "
"children_system=%.2f" %
(cpu_times.user, cpu_times.system,
cpu_times.children_user,
cpu_times.children_system))
self.cpu_times['user'] += cpu_times.user
self.cpu_times['system'] += cpu_times.system
self.cpu_times['children_user'] += cpu_times.children_user
self.cpu_times['children_system'] += cpu_times.children_system
try:
cpu_times = self.proc.cpu_times()
self.log.debug("Ansible cpu times: user=%.2f, system=%.2f, "
"children_user=%.2f, "
"children_system=%.2f" %
(cpu_times.user, cpu_times.system,
cpu_times.children_user,
cpu_times.children_system))
self.cpu_times['user'] += cpu_times.user
self.cpu_times['system'] += cpu_times.system
self.cpu_times['children_user'] += cpu_times.children_user
self.cpu_times['children_system'] += cpu_times.children_system
except psutil.NoSuchProcess:
self.log.warn("Cannot get cpu_times for process %d. Is your"
"/proc mounted with hidepid=2"
" on an old linux kernel?", self.proc.pid)
ret = self.proc.wait()
self.log.debug("Ansible exit code: %s" % (ret,))
finally: