Skip to content

The timeout given to evaluate stops the evaluation between steps - #2093

Merged
rocky merged 2 commits into
masterfrom
fix-evaluate-timeout
Oct 30, 2026
Merged

rocky merged 2 commits into
masterfrom
fix-evaluate-timeout

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

Evaluation.evaluate(query, timeout=...) (and MathicsSession.evaluate_as_in_cli(..., timeout=...)) never used its timeout; nothing stopped the evaluation when it ran out. A caller that wanted a limit had to interrupt from outside, e.g. with SIGALRM, at an arbitrary point in the Python code. An interrupt in the middle of an iteration step could leave Table's step counter as an unevaluated Plus[...], which then crashed eval_iter with TypeError: '>' not supported between instances of 'NoneType' and 'int'. I hit this while running the examples of Computational Discrete Mathematics with Combinatorica, with a per-cell time limit.

  • The timeout is now a deadline that check_stopped checks, between evaluation steps. The evaluation ends with $Aborted and General::timeout, and the deadline is cleared, so the next evaluation has no limit left over.
  • The iterator's step counter is now a Python int. This also saves evaluating Plus[index, 1] on every step.

settings.TIMEOUT is None by default, so the CLI and REPL behave as before.

New test: Do[k^2, {k, 10^7}] and a Table of Timings with timeout=0.3 give $Aborted and "Timeout reached." in 0.3 s, and the next evaluation runs without a limit.

🤖 Generated with Claude Code

Evaluation.evaluate(query, timeout=...) never used its timeout, so a
caller that wanted a limit had to interrupt from outside, at any point in
the Python code. An interrupt in the middle of an iteration step left
Table's counter as an unevaluated Plus[...] and crashed with a TypeError.

The timeout is now a deadline checked in check_stopped, between
evaluation steps, and ends the evaluation with $Aborted and
General::timeout. The iterator's step counter is kept as a Python int,
which also saves evaluating Plus[index, 1] on each step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mmatera

mmatera commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@tombouctou, thanks for checking this out. Currently, timeout is implemented using stopit. The function doing this task is in

if sys.platform == "emscripten":

At some point we move the call into the code of TimeConstrained, and forgot to handle the timeout parameter in the evaluation.

@rocky

rocky commented Oct 30, 2026

Copy link
Copy Markdown
Member

LGTM. And thanks!

@rocky
rocky merged commit fdd5b8a into master Oct 30, 2026
15 checks passed
@rocky
rocky deleted the fix-evaluate-timeout branch October 30, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants