Cancel or timeout a long running regular expression

Chris Angelico rosuav at gmail.com
Fri Sep 16 00:32:53 CEST 2011


On Fri, Sep 16, 2011 at 4:54 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 9/15/2011 1:19 AM, python at bdurham.com 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
that.)

ChrisA



More information about the Python-list mailing list