Pathological regular expression

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Apr 11 20:31:44 EDT 2009


On Sat, 11 Apr 2009 16:46:20 -0700, John Machin wrote:

> On Apr 12, 3:40 am, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote:
>> >> To my mind, this is a bug in the RE engine. Is there any reason to
>> >> not treat it as a bug?
>>
>> > IMHO it's not a bug -- s/hang/takes a long time to compute/
>>
>> > Just look at it: 2 + operators and 3 * operators ... It's one of
>> > those "come back after lunch" REs.
>>
>> Well, it's been running now for about two and a half hours, that's a
>> rather long lunch. And despite MRAB's assertion, it *cannot* be
>> interrupted by ctrl-C. That means that to all intents and purposes, the
>> interpreter has locked up for the duration of the calculation, which
>> may be days or weeks for all I know.
> 
> If you don't know, experiment!

My original test has now been running for close to ten hours now, and 
still can't be interrupted with ctrl-C. However that's in Python 2.5, 
having tried it in Python 2.6.2 they can be interrupted, so I'm satisfied 
that this bug of "regex hangs the interpreter" is not worth reporting, as 
it effects only older versions.

[...]

> 3. Test the RE, get it correct

They're not my regexes. I don't care whether they are correct or not, I'm 
more concerned about them locking up the interpreter.


-- 
Steven



More information about the Python-list mailing list