
18 Oct
2010
18 Oct
'10
9:51 a.m.
Nikolaus Rath Nikolaus@rath.org writes:
I a thread does not hold the GIL, is it totally forbidden to call any Py* API functions at all, or are there some exceptions?
More concretely, am I allowed to create fresh Python objects with PyBytes_FromString et. al. without holding the GIL?
You are not allowed to create fresh Python objects without holding the GIL. The objects might implement a caching strategy which would surely rely on the GIL for locking.
The only Python API calls that could conceivably be safe without holding the GIL are accessors to C members of immutable objects whose reference you're owning - say, PyString_AS_STRING, or PyInt_AS_LONG.