-
Notifications
You must be signed in to change notification settings - Fork 40
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
Silent evaluation failures due to too low recursion-limit(100) #21
Comments
+ See: https://github.com/newville/asteval/issues/21 - Only 1 xleash-TC still failing.
@ankostis @dwelch91 Hm, that seems weird. First, the failure shouldn't be silent. But I don't know why this didn't raise a RecursionError. Perhaps that was somehow suppressed? That should be fixed for sure. Limiting the recursion depth was added earlier this year as part #17, and is part of the effort to prevent seg-faulting Python. I don't have a strong opinion on what that actual limit is. With Pythons default of 1000, 100 seems reasonable for asteval, though I suppose 500 is also reasonable. It's also reasonable to say that we should not change this limit at all. If we do set the value, I think it is better to set this limit and then re-set it back to the previous value for each The "current stack depth" from len(inspect.stack()) tells you how deep you are into nested function calls. I'm not sure you want to use that as a basis for how much further you want to go -- I think you want to set a hard limit. Like, if you're only in 1 or 2 levels, 100 doesn't matter, but if you're already in 400 levels, do you really want to set the limit to 100 more? I would ask, how the heck did you get to creating an instance of asteval.Interpreter() 400 calls in deep from the top-level of the process. It would be fine to make this user-configurable. There have been other suggestions for more initialization-time configuration, including what language features to support -- including recursion limit would be fine too. The challenge is that there are a lot of potential configuration options, so it might be best to use something other than arguments to Updates to code or documentation welcome! |
I had always encounter the following error:
I agree with that 100 is too low. |
@newville while trying to craft a PR, I noticed that Is that on purpose? |
Anyhow, #22 is served. If you want me also to de-duplicate |
+ Separate public/private function parse()/run()/eval() methods. Only public methods enforce recursion-limit. + Use `contextlib` for setting recurse-limit temporariyl. + Strengthen related TCs bychecking recurse-limit indeed restored.
Reporting also a non-fatal bug discovered during #22:: The setting/resetting of the recursion-limit happens on every |
+ Was invoked multiple times per each eval (at least 4, more if was calling user-defined functions). + It is difficult to come up with a sensible value for limit, and whether that should be *in addition* to the current stack-depth (see discussion in lmfit#22 PR). + No TCs affected. `test-dos()` elapsed time remained the same(!). + Will add a "recipe" for how to set the recurse-limit externally in client-code.
…recursion-limit. + minor: Replaced doc-title's surrounding chars (= --> #) to fix LiClipse's HTML-previewer; is renders title as section title, probably due to a bad interaction of the 2 opening links and header-underline chars being the same ('=').
since newville/asteval#21 has been resolved on 0.9.8+ (Sep2016).
since newville/asteval#21 has been resolved on 0.9.8+ (Sep2016).
since newville/asteval#21 has been resolved on 0.9.8+ (Sep2016).
- 0.9.7 (Apr 2016): support 3.5+ - 0.9.8 (Sep 2016): recursion bad code removed (could not recurse deep before) newville/asteval#21 - 0.9.10 (Oct 2017): usersym table
While evaluating correct expressions, I got
None
as result, but no error were reported (they have silently failed).When I tried to investigate the issue, I was receiving the following error on
Interpreter().eval()
from within my debugger (LiClipse + PyDev):Obviously my debugger had pushed the stack close to that limit,
and python-interpreter screamed at asteval/asteval.py#L136:
So I hand-edited asteval/astutils.py:#L16 and increased my limit to i.e. 500:
But then, all my expressions worked OK!
On first impression, I would consider
recursion-limit=100
, too low for general use.My second thought would be to set the limit at least
current_stack_depth + 100
and that value(100) to be user-configurable.But as general precaution, I believe that:
normal code should not mess with
sys.setrecursionlimit()
because it might have serious side-effects.If this protection measure is needed, user-code should perform that invocation - the documents should explain how.
At most, an "opt-in" keyword should do that, with something like that:
The text was updated successfully, but these errors were encountered: