Timeout for regular expression

Fredrik Lundh fredrik at pythonware.com
Tue Nov 22 18:49:15 CET 2005


<citronelu at yahoo.com> wrote

> Is there a way to set a timeout interval when executing with a
> re.search ? Sometimes (reason being maybe a "bad" pattern),
> the search takes forever and beyond...

not directly.  the only reliable way is to run it in a separate process,
and use the resource module to set necessary limits.

(to figure out if an expression can take lots of time, look for nested
repeats.  analyzing the output from sre_parse.parse(pattern) makes
that relatively easy).

</F> 






More information about the Python-list mailing list