<div dir="ltr">Hi all,<div><br>one of our Python projects calls for pretty heavy, low-level optimizations.</div><div><br></div><div>We went down the rabbit hole and determined that having access to PyList_GET_ITEM(list), PyInt_AS_LONG(int) and PyDict_GetItem(dict, unicode) on Python objects **outside of GIL** might be a good-enough solution. The Python objects in question are guaranteed to live and not be mutated externally in any way. They're "frozen" and read-only.</div><div><br></div><div>Under what conditions is it OK to call these 3 functions on such objects?</div><div><br></div><div>More generally, what is the CPython 2.7/3.5 contract regarding (lack of) object mutation, and the need for reference counting and synchronization via GIL?</div><div><br></div><div>Which C API functions are safe to call on "const" objects?</div><div><br></div><div>Obviously releasing GIL and then calling C API is hacky, but from initial experiments, it seems to work (see <a href="https://stackoverflow.com/questions/51351609/can-i-const-access-cpython-objects-without-gil">https://stackoverflow.com/questions/51351609/can-i-const-access-cpython-objects-without-gil</a>). But I'm wondering if there's a more formal contract around this behaviour.</div><div><div><br></div><div>Cheers,</div><div>Radim</div><div><br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-family:Arial,sans-serif;line-height:17.7273px"></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div></div></div>