Is re thread-safe?
jepler at unpythonic.net
Thu Dec 25 03:38:41 CET 2003
I don't know of anything about regular expression objects that would not
be thread safe. They don't have any data attributes that depend on the
current or last matching operation, for instance.
Internally, the C implementation of regular expressions is either
thread-safe or else runs with Python's GIL held to avoid thread-safety
It's possible that there's a particular concern I've overlooked--for
instance, REs can refer to character classes such as "alphanumeric"
(with \w, it looks like [:CLASS:]es are not supported). That means that
the meaning of a regular expression can depend on the state of the
program's locale, which is not a per-thread attribute.
More information about the Python-list