-
Notifications
You must be signed in to change notification settings - Fork 37
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
Failing to timeout regex? #12
Comments
I have encountered this behaviour under the following circumstances:
Code example: import re
from func_timeout import func_timeout, FunctionTimedOut
from timeit import default_timer as timer
if __name__ == '__main__':
my_regex = '^(a|a?)+b$'
text = 'aaaaaaaaaaaaaaaaaaaaaaaa'
max_timeout = 1
start = timer()
try:
func_timeout(max_timeout,re.search, (my_regex,text) )
except FunctionTimedOut:
print('Time exceeded')
end = timer()
print(end-start) |
Func_timeout only has a chance to stop function between python instructions. If the call is stuck in libpython C code, it must return to the python stack before it can be terminated. |
Thank you for the clear, concise explanation @kata198 ! |
Howdy! Thanks for your work on this projec!
I'm honestly not sure if I've found a bug or if I'm misunderstanding the usage of the decorator. I'm trying to use
func_set_timeout()
to timeout some catastrophically backtracking regexes. (They scale of O(2^n), nasty little things) However, in my tests the decorator works just fine on a sleep function but doesn't catch the regex. In fact the process has to be killed from another shell.Execution environment:
Terminal output:
Is this related to #10? I don't think it is since that's really specific to Python2 and this is 3.7.5. Have I missed something in the README? Did I find a bug? Is my execution environment just a wacky snowflake?
Thanks again for your work!
The text was updated successfully, but these errors were encountered: