-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Limit TimeConstrained to one per eval. #1202
base: master
Are you sure you want to change the base?
Conversation
0cd97b0
to
af3fc4b
Compare
mathics/builtin/datentime.py
Outdated
done = False | ||
if self.is_running_TimeConstrained: |
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.
A way to check if we have already set a time constraint is to check the length of evaluation.timeout_queue
. I remember that with the previous implementation, this kind of nested constraint used to work.
At least locally, with the version in the master branch,
work as expected. The issue seems to happen when both wall times are similar, and coincides with the time that
produces the exception one-third of the time. Probably, the way to handle this is just by capturing that exception. |
"At least locally" isn't good enough. Recall that we have also been seeing failures in CI tests with TimeConstraint. Right now, my goal is to have something that unblocks @aravindh-krishnamoorthy. For this, there does not have to be a long-term solution. If this branch works, it can stay a branch and not get merge. If checking
Looking for specific exceptions is hacky and fragile. A solution like this is likely to break on different Python versions, Python implementations, and Operating Systems. This kind of thinking (it seems to work here - I just need to hack some special cases) leads us down a rabbit hole that I don't think we'll be ever able to climb back out of. What I'd like to see is something general and simple, and that can work with Rubi. If we have to sacrifice powerfulness, and Rubi searching quality that's okay. Once we have something working we can try to improve things. |
af3fc4b
to
390f7ea
Compare
@rocky , what I was trying to understand is what is the actual problem with nested |
glenfant/stopit#17 suggests that others have had a problem when nesting in the same thread. |
Hello @rocky. Firstly, thank you very much for identifying the underlying cause and unblocking me. Indeed, with this fix, Rubi This fix breaks the function I'll try to get |
I suspect we can get a better TimeConstrained function by having it create a new thread (up to some limit) for each expression that is to be time constrained. However, please let's not do this right now but, as you suggest, leave this for later as a second step. We have lots out-right bugs in the code and missing functionality in certain built-in functions. If we could remove more of those first and get some sort of Rubi subset going, this would be great.
Thanks. But also please, look for how we can break this large task into smaller well-defined pieces. Maybe just the first two or three sections of 1 Algebraic functions. The list in |
Yep. The old code I wrote handle this by keeping a queue of calls, and using different threads on each call. Maybe during my holidays I can try to propose a fix for stopit, but I need to study better how is currently implemented. |
In the above commits (16de5ec, be4fe46), during a recursive call, instead of returning With this change, a mini-test with I'll now run the full |
Getting a fix/PR for in the stopit repository would be awesome. That code hasn't significantly changed in about 6 years or when Python 3.6 was around. Python has probably changed threading since then and different kinds of threads used in Python is on the horizon. |
Unfortunately, there still seems to be an issue. The issue is not immediately apparent. When running long Rubi tests, |
…hics-core into at-most-one-TimeConstrained
I need more information here. If you have logs that show both what what you invoked and what you got, that would be helpful. Why is TraceEvaluation needed? Finally, I should mention that signal handling was added to the Mathics debugger. Here again is how to use this: Without the debugger, but with If you want to go into the debugger and look at |
Very sorry for this, @rocky. I actually meant
I'm working on finding a small reproducible example. But this seems to happen randomly, which makes debugging a bit difficult. |
An idea which I haven't tested yet. Maybe you can implement |
Allowing a TimeConstrained evaluation to contain another TimeConstrained evalution is tricky. We would have on the second Timeconstrained while one is already pending would force us to not blindly set SIGALRM but instead figure out which ALARM comes earlier and when that is hit handle the TimeConstrained and queue another SIGLARM the amout of time of the second evaluation.
So for now, punt and just don't allow a second TimeConstrained to run but instead return failure.