[Python-Dev] GIL required for _all_ Python calls?

"Martin v. Löwis" martin at v.loewis.de
Thu Jan 7 21:45:42 CET 2010

>>> I've been wondering whether it's possible to release the GIL in the
>>> regex engine during matching.
>> I don't think that's possible. The regex engine can also operate on
>> objects whose representation may move in memory when you don't hold
>> the GIL (e.g. buffers that get mutated). Even if they stay in place -
>> if their contents changes, regex results may be confusing.
> It seems probably worthwhile to optimize for the common case of using
> the regexp engine on an immutable object of type "str" or "bytes", and
> allow releasing the GIL in *that* case, even if you have to keep it for
> the general case.

Right. This problem was the one that I thought of first.

Thinking about these things is fairly difficult (to me, at least), so
I think I could only tell whether I would consider a patch thread-safe
that released the GIL around matching under selected circumstances -
if I had the patch available. I don't see any obvious reason (assuming
Guido's list of conditions holds - i.e. you are holding references to
everything you access).


More information about the Python-Dev mailing list