pexpect: Check if the process exited with a signal

This would have been helpful in #10044:

> signals.py:28: SIGNAL SIGSEGV from expect_prompt()

instead of "EOF".
This commit is contained in:
Fabian Boehm 2023-10-04 16:02:13 +02:00
parent f8e38819a5
commit 7a22dcb687

View file

@ -22,6 +22,7 @@ import re
import sys
import time
import pexpect
from signal import Signals
# Default timeout for failing to match.
TIMEOUT_SECS = 5
@ -246,8 +247,15 @@ class SpawnedProc(object):
Report it to stdout, along with the offending call site.
If 'unmatched' is set, print it to stdout.
"""
# Close the process so we can get the status
self.spawn.close()
colors = self.colors()
failtype = pexpect_error_type(err)
# If we get an EOF, we check if the process exited with a signal.
# This shows us e.g. if it crashed
if failtype == 'EOF' and self.spawn.signalstatus != 0:
failtype = "SIGNAL " + Signals(self.spawn.signalstatus).name
fmtkeys = {"failtype": failtype, "pat": escape(pat)}
fmtkeys.update(**colors)