-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handling TimeConstrained[]
in SymPy evaluation
#1160
Conversation
@davidar, ideas about how to implement this in Pyodide are welcome. |
Unfortunately I don't think there is a good solution to that in pyodide yet, at least not without cooperation from the javascript environment hosting the pyodide interpreter (https://pyodide.org/en/stable/usage/keyboard-interrupts.html). Might just need to disable it in pyodide for now. |
@davidar Thanks for the information and link. It confirms what I had meant to look up. What Mathics3 should do is provide a signal-handling mechanism that causes the current computation to stop after a certain amount of time (SIGALRM). Mathics3 should also trap other signals like SIGINT. In wolframscript, Ctrl-C (SIGINT) goes into an Interrupt prompt. Later, we should provide a compatible (and possibly much better) interrupt interface. If I have this correct, the link you have indicates that pyodide does provide a means for sending trapping and sending signals back to Python. One other thing to note about Python's signal handling - only the main thread can trap signals. I don't think this is a problem, just something to note. With this we can provide a somewhat coarse mechanism for handling timeouts that is compatible with pyodide. @mmatera Now that you may have been just informed about signal handling and timeouts, please don't jump ahead and start implementing this in code. (If you want to experiment privately - by all means go ahead.) If there is a need right now for TimeConstrained, I'd appreciate knowing what the deal is. |
@mmatera Please give me a couple of days for me to pull down this branch to try out. Thanks. |
TimeConstrained[]
in SymPy evaluation
Sure, no hurry. I just put this because when I looked over the issue with |
|
||
# Consider testing via unit tests. | ||
# >> TimeConstrained[Integrate[Sin[x]^1000000,x],1] | ||
# = $Aborted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried
TimeConstrained[Integrate[Sin[x]^1000000,x],1]
I am getting a RecursionError that is not handled. Worse is that calls with_traceback()
with the wrong number of parameters. A PR has been created to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, with Pyston I got a core dump for that test. But it is reasonable: Sympy does not control by itself how much memory/work needs to converge.
An idea to fix
TimeConstrained
and related functions, at least for evaluations involving sympy.Still I can produce a core dump if I ask for a ridiculus task in Sympy, but is a problem of Sympy, not from Mathics