Time out a regular expression in Python 2.6.4?

Steve Holden steve at holdenweb.com
Mon Feb 15 16:59:22 CET 2010

python at bdurham.com wrote:
> Is there any way to time out a regular expression in Python 2.6.4?
> Motiviation: Our application allows users to enter regular expressions
> as validation criteria. If a user enters a pathological regular
> expression, we would like to timeout the evaluation of this expression
> after a short period of time.
Python itself does not contain any mechanism to terminate an operation
if it takes too much time.

One approach would be to run the regex in a subprocess, and apply
process limits to terminate that subprocess if it ran too long.

This group being what it is you are likely to receive other, better
suggestions too.

Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

More information about the Python-list mailing list