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

Antoine Pitrou solipsis at pitrou.net
Thu Jan 7 16:38:31 CET 2010

MRAB <python <at> mrabarnett.plus.com> writes:
> I know that it needs to have the GIL during memory-management calls, but
> does it for calls like Py_UNICODE_TOLOWER or PyErr_SetString? Is there
> an easy way to find out?

There is no "easy way" to do so. The only safe way is to examine all the
functions or macros you want to call with the GIL released, and assess whether
it is safe to call them. As already pointed out, no reference count should be
changed, and generally no mutable container should be accessed, except if that
container is known not to be referenced anywhere else (that would be the case
for e.g. a list that your function has created and is busy populating).

I agree that releasing the GIL when doing non-trivial regex searches is a
worthwhile research, so please don't give up immediately :-)


Antoine Pitrou.

More information about the Python-Dev mailing list