Check for signals during regular expression matches #39573
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = 'https://github.com/facundobatista' closed_at = <Date 2008-01-09.14:22:46.703> created_at = <Date 2003-11-21.06:29:21.000> labels = ['interpreter-core'] title = 'Check for signals during regular expression matches' updated_at = <Date 2008-02-05.04:13:26.208> user = 'https://bugs.python.org/joshhoyt'
activity = <Date 2008-02-05.04:13:26.208> actor = 'gvanrossum' assignee = 'facundobatista' closed = True closed_date = <Date 2008-01-09.14:22:46.703> closer = 'facundobatista' components = ['Interpreter Core'] creation = <Date 2003-11-21.06:29:21.000> creator = 'joshhoyt' dependencies =  files = ['5695', '8679', '8680', '9064'] hgrepos =  issue_num = 846388 keywords = ['patch'] message_count = 12.0 messages = ['44910', '44911', '44912', '57056', '57067', '57068', '59246', '59247', '59267', '59600', '61925', '62062'] nosy_count = 6.0 nosy_names = ['gvanrossum', 'loewis', 'effbot', 'facundobatista', 'joshhoyt', 'schmir'] pr_nums =  priority = 'normal' resolution = 'fixed' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue846388' versions = ['Python 2.4']
The text was updated successfully, but these errors were encountered:
This patch adds a call to PyErr_CheckSignals to
Regular expressions can run away inside of the C code.
When the signal was received, the signal function was
I am unsure whether the PyErr_CheckSignals is
here is an example (from http://swtch.com/~rsc/regexp/regexp1.html)
python -c 'import re; num=25; r=re.compile("a?"*num+"a"*num);
At work I have seen a real world case of a regular expression which ran
I'm attaching a working patch against 2.5.1 and a short test program.
#! /usr/bin/env python
import signal import re import time def main(): num=28 # need more than 60s on a 2.4Ghz core 2 r=re.compile("a?"*num+"a"*num) signal.signal(signal.SIGALRM, signal.default_int_handler) signal.alarm(1) stime = time.time() try: r.match("a"*num) except KeyboardInterrupt: assert time.time()-stime<3 else: raise RuntimeError("no keyboard interrupt") if __name__=='__main__': main()
Couldn't apply cleanly the patch, as it appears to be a diff in other
Anyway, applied it by hand, and now I attach the correct svn diff.
The test cases run ok with this change, and the problem is solved.
Regarding the delay introduced, I tested it with:
$ ./python timeit.py -s "import re;r=re.compile('a?a?a?a?a?aaaaa')" "r.match('aaaaa')"
I don't like that. Anyway, I do NOT trust for timing the system where
./python Lib/timeit.py -n 1000000 -s "import
which would be ok, I guess.
(This is on a 64bit debian testing with gcc 4.2.3).
Can you test with the following:
if ((0 == (sigcount & 0xffffffff)) && PyErr_CheckSignals())
(i.e. the code will (nearly) not even call PyErr_CheckSignals).
I guess this is some c compiler optimization issue (seems like mine does