Replies: 2 comments 6 replies
-
Nothing built in for this but you can put the Julia object as an attribute on the Python object whose lifetime you want to tie it to. Or use a WeakKeyDict with the Python object as a key and Julia object as a value. |
Beta Was this translation helpful? Give feedback.
-
I'm writing a package that allows to share tensors (including GPU lived ones) without copying the data, both from julia to python and the other way around (https://github.com/pabloferz/DLPack.jl). There is a C API for this that many libraries such as jax, pytorch, cupy, etc. support. The conventions to perform data sharing through this API are described here https://data-apis.org/array-api/latest/design_topics/data_interchange.html. I can wrap python tensors already and access them from julia with both PyCall and PythonCall. For sharing from julia to python I need to generate the python objects each library provide (I can already do this), but I would like to keep the julia arrays around at least for as long as the corresponding python tensors live. In PyCall I can call |
Beta Was this translation helpful? Give feedback.
-
Is there a way to keep a julia object around, e.g. within
PYJLVALUES
and remove it once a python object gets garbage collected via a weak reference (something similar toPyCall.pyembed
)?Beta Was this translation helpful? Give feedback.
All reactions