Does a '_sre.SRE_Pattern' have state,or is it thread-safe?
MRAB
python at mrabarnett.plus.com
Wed Jun 23 13:40:21 EDT 2010
John Nagle wrote:
> '_sre.SRE_Pattern' is what "re.compile" returns.
>
> Is that a mutable object, with state that changes
> during the parse, or is it an immutable constant? Can
> two threads use the same '_sre.SRE_Pattern' at the same time?
>
> (I'm writing something to find race conditions in existing code,
> which is why all these obscure introspection-related questions.)
>
A compiled pattern instance is immutable and threadsafe.
BTW, its methods don't release the GIL, so even if it wasn't threadsafe,
it would still be safe. :-)
More information about the Python-list
mailing list