Cancel or timeout a long running regular expression

Chris Angelico rosuav at
Thu Sep 15 18:32:53 EDT 2011

On Fri, Sep 16, 2011 at 4:54 AM, Terry Reedy <tjreedy at> wrote:
> On 9/15/2011 1:19 AM, python at wrote:
>> 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.
> Only solution I remember ever seen posted.

Then here's a minor refinement. Since long-running RE is the
exceptional case, optimize for the other. Keep the process around and
feed it all the jobs you get, and on problem, kill and respawn. That
way, you pay most of the overhead cost only when you make use of the
separation. (There's still some IPC overhead of course. Can't escape


More information about the Python-list mailing list