-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clone
(or alternative) on GILOnceCell
#4428
Comments
This is a great question. The A related question is what to do about |
Thanks for the response, and sorry for disappearing for a long while there! I made #4511 with the top bullet, but happy to change it however needed. For |
I think for |
I have a
pyclass
struct that wants to contain aGILOnceCell<Py<PyAny>>
for caching of a lazily constructed Python object, where the initialiser yields control to the Python interpreter so runs the risk of re-entrancy problems with regularOnceCell
.I'd originally tried to derive
Clone
on my struct (I'm still usingpy-clone
for the time being, but working to disentangle our data structures), which if I understand correctly must fail forGILOnceCell
because it requires the GIL to mediate both gets and sets. For the time being, I think the correct course of action for me for the clone is to manuallyGILOnceCell::new(other_cell.get(py).map(|ob| ob.clone_ref(py)))
(or similar).edit: if there's an A/B problem here, and there's something better I could be doing with this kind of cache, I'm totally open to alternatives to the answer being "that's not the right way to do this".
Would it be possible to either:
impl<T> GILOnceCell<Py<T>> { pub fn clone_ref(&self, py: Python); }
method doing what I sketched?GILOnceCell
the proposedderive
macro for this kind of "clone with the GIL", if that is what comes out of Add trait for cloning while the GIL is held #4133?The text was updated successfully, but these errors were encountered: