python 子线程coredump_Python os.WCOREDUMP属性代码示例

# 需要导入模块: 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值