Cancel or timeout a long running regular expression

python at python at
Thu Sep 15 01:19:20 EDT 2011

Is there a way to cancel or timeout a long running regular

I have a program that accepts regular expressions from users and
I'm concerned about how to handle worst case regular expressions
that seem to run forever. Ideally I'm looking for a way to
evaluate a regular expression and timeout after a specified time
period if the regular expression hasn't completed yet. Or a way
for a user to cancel a long running regular expression.

I was thinking there might be a technique I could use to evaluate
regular expressions in a thread or another process launched via
multiprocessing module and then kill the thread/process after a
specified timeout period. My concern about the multiprocessing
module technique is that launching a process for every regex
evaluation sounds pretty inefficient. And I don't think the
threading module supports the ability to kill threads from
outside a thread itself.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list