From cf55b385b81e85f284d52b6764ea808e6e39bba9 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 16 Oct 2024 16:55:31 -0400 Subject: [PATCH] src/sage/doctest/forker.py: re-raise SignalErrors If SystemExit occurs during a doctest, we re-raise it. The same thing should be done for SignalError (from cysignals). Signals can occur at any time, and the doctest runner shouldn't eat them. In particular, this can lead to a Heisenbug where a signal will terminate a doctest example before the timer has a chance to annotate the it with the elapsed walltime and cputime. In that case, we get an "impossible" AttributeError later on when we try to compute the total walltime used by the example. --- src/sage/doctest/forker.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 8bddadc1f48..dfdb4cc8899 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -709,10 +709,12 @@ def compiler(example): elif self.options.gc < 0: gc.disable() + from cysignals.signals import SignalError try: # Don't blink! This is where the user's code gets run. self.compile_and_execute(example, compiler, test.globs) - except SystemExit: + except (SignalError, SystemExit): + # Tests can be killed by signals in unexpected places. raise except BaseException: exception = sys.exc_info()