# 需要导入模块: import os [as 别名]
# 或者: from os import WCOREDUMP [as 别名]
def run(self):
"""
self.exit_status = os.waitpid(self.pid, os.WNOHANG | os.WUNTRACED)
while self.exit_status == (0, 0):
self.exit_status = os.waitpid(self.pid, os.WNOHANG | os.WUNTRACED)
"""
self.spawn_target()
self.finished_starting.set()
if self.proc_name:
gone, _ = psutil.wait_procs([self._psutil_proc])
self.exit_status = gone[0].returncode
else:
exit_info = os.waitpid(self.pid, 0)
self.exit_status = exit_info[1] # [0] is the pid
default_reason = "Process died for unknown reason"
if self.exit_status is not None:
if os.WCOREDUMP(self.exit_status):
reason = "Segmentation fault"
elif os.WIFSTOPPED(self.exit_status):
reason = "Stopped with signal " + str(os.WTERMSIG(self.exit_status))
elif os.WIFSIGNALED(self.exit_status):
reason = "Terminated with signal " + str(os.WTERMSIG(self.exit_status))
elif os.WIFEXITED(self.exit_status):
reason = "Exit with code - " + str(os.WEXITSTATUS(self.exit_status))
else:
reason = default_reason
else:
reason = default_reason
outdata = None
errdata = None
try:
if self._process is not None:
outdata, errdata = self._process.communicate(timeout=POPEN_COMMUNICATE_TIMEOUT_FOR_ALREADY_DEAD_TASK)
except subprocess.TimeoutExpired:
self.process_monitor.log(
msg="Expired waiting for process {0} to terminate".format(self._process.pid), level=1
)
msg = "[{0}] Crash. Exit code: {1}. Reason - {2}\n".format(
time.strftime("%I:%M.%S"), self.exit_status if self.exit_status is not None else "", reason
)
if errdata is not None:
msg += "STDERR:\n{0}\n".format(errdata.decode("ascii"))
if outdata is not None:
msg += "STDOUT:\n{0}\n".format(outdata.decode("ascii"))
self.process_monitor.last_synopsis = msg