regex - Is Python re thread-safe? -
i tried googling gotten no authoritative answer.
can confirm re
module http://docs.python.org/2/library/re.html thread-safe?
more specifically, functions , not?
also, can reuse single global compiled re object sub
, search
, etc. safely across threads?
seems there still no clear answer?
ok, more specific example:
class myclass: global_var = re.compile(...) def clean(self, value): return myclass.global_var.sub('', value)
will work expected when multiple threads call clean @ same time?
i don't think there is authoritative answer—other digging around in source, gets answers existing versions of python not future ones—since @ least parts of versions of regular expression module written in c (at least cpython; jython, instance, knows?) , nobody seems have made promises them.
in practice have not seen bits of re code not thread-safe, , later example global_var.sub
call "almost certainly" thread-safe. ... there's still darned lack of written promises. :-)
Comments
Post a Comment