Skip to content

Commit

Permalink
src/sage/doctest/forker.py: re-raise SignalErrors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orlitzky committed Oct 16, 2024
1 parent 7aa6be8 commit cf55b38
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cf55b38

Please sign in to comment.