osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Const access to CPython objects outside of GIL?


On Wed, Jul 18, 2018 at 8:18 PM, Radim ?eh??ek
<radim at rare-technologies.com> wrote:
> Thanks for your feedback everyone. Given the overwhelmingly negative
> response, we'll drop this line of investigation.
>
> If more people bring up the same request in the future (unlikely), feel free
> to reach out to us for some extra set of hands. Given the initial poking, I
> still think a "reasonable subset" might be "reasonably easy"; IMHO more a
> process/maintenance/ROI question than a strictly technical one.

The trouble would be defining that "reasonable subset", which would
end up having a very large number of words in it. For example,
accessing a Python list after any sort of size change could crash the
interpreter hard (as the buffer will have been reallocated). I'm
fairly sure you can safely read from a tuple so long as you retain a
ref to the tuple itself, though, so you may find that there are
options there.

Maybe, depending on your needs, the best solution might be to NOT
access Python objects at all. Instead, have an API for changing info
that is referenced outside of the GIL, and then the key info gets
grabbed in a form that doesn't require Python. That would require some
changes in the Python code (function calls rather than list
manipulation), but would be 100% guaranteed safe. But you've probably
already thought of that, so this is a case where that doesn't work :)

ChrisA