Regular Expressions and Threads?

Aahz Maruch aahz at netcom.com
Wed Jun 14 20:16:55 EDT 2000


In article <39481F1C.419364F5 at uswest.net>,
Brian Wisti  <wbrian2 at uswest.net> wrote:
>Aahz Maruch wrote:
>>
>> I doubt your problem has to do with threads; I bet that if you took your
>> code and ran it unthreaded you would have the same problem.  From your
>> description, it sounds like you have a list variable that you're
>> appending to and not resetting after you do the string.join().  If
>> that's not it, I don't have any better ideas without code.
>
>You may be correct... however, the only way I was able to fix the
>problem was with an ugly hack:
>
>	re._cache.clear()
>
>Ugly because it's undocumented, and that means I should keep my grubby
>little paws away from it. Ugly or not, once I put this line in,
>everything has gone peachy.

Umph.  Well, then, did you double-check to make sure you're not sharing
the same re object between threads?  If you're doing anything more than
checking for the existence of a match, that could cause problems.  (As
with anything else, the re module should be thread-safe, but individual
re objects probably are not.)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"real love can't be explained by simplistic platitudes."  --piranha



More information about the Python-list mailing list