Repository navigation
The timeout given to evaluate stops the evaluation between steps - #2093
Merged
Merged
Conversation
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>
Contributor
|
@tombouctou, thanks for checking this out. Currently, timeout is implemented using mathics-core/mathics/eval/datetime.py Line 68 in 7286b06 At some point we move the call into the code of TimeConstrained, and forgot to handle the timeout parameter in the evaluation. |
Member
|
LGTM. And thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Evaluation.evaluate(query, timeout=...)(andMathicsSession.evaluate_as_in_cli(..., timeout=...)) never used itstimeout; 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 leaveTable's step counter as an unevaluatedPlus[...], which then crashedeval_iterwithTypeError: '>' 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.check_stoppedchecks, between evaluation steps. The evaluation ends with$AbortedandGeneral::timeout, and the deadline is cleared, so the next evaluation has no limit left over.Plus[index, 1]on every step.settings.TIMEOUTisNoneby default, so the CLI and REPL behave as before.New test:
Do[k^2, {k, 10^7}]and aTableofTimings withtimeout=0.3give$Abortedand "Timeout reached." in 0.3 s, and the next evaluation runs without a limit.🤖 Generated with Claude Code