-
Notifications
You must be signed in to change notification settings - Fork 791
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
Enable GILProtected
access via PyVisit
#3616
Conversation
d100f16
to
5de907c
Compare
I am 100% willing to change the name of the method. I just wanted the MR to go with the issue ASAP so both can be closed quickly (assuming there is little to no need to discuss the feature). |
5de907c
to
2940e19
Compare
I'm feeling split about this feature. I understand why in practice this seems ok at the moment, but can we really rely on the fact that the GC will never traverse the graph in parallel? Can you give some use cases of what you need this for? With the advent of nogil, we sort of need to be killing |
If we can't, then PyO3 already has a major issue around marking types as EDIT: Ironically, reading PEP 703, it sounds like even with nogil all other Python threads will be paused during cycle detection.
Any time you have any Python object behind a struct Inner {
items: VecDeque<PyObject>,
}
#[pyclass]
struct Sender {
inner: Arc<GILProtected<RefCell<Inner>>>,
}
#[pymethods]
impl Sender {
fn send(&self, py: Python<'_>, obj: PyObject) {
self.inner.get(py).borrow_mut().items.push_back(obj);
}
fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
// unable to traverse objects in the queue
}
fn __clear__(&mut self, py: Python<'_>) {
self.inner.get(py).borrow_mut().items.clear();
}
}
I don't necessarily see that as an issue in this MR. When PEP 703 does land, my money is on it taking a while for it to actually be used and, more importantly, that's a massive, fundamental, update to PyO3. It doesn't seem to me that a three line convenience function should be blocked by something that big and far away. |
Fair points! Good thought about I think for practicality's sake I'm happy to move forward here with the name |
2940e19
to
4e8b881
Compare
Please also fix the reference to the original method name in the changelog entry. Thanks! |
Closes PyO3#3615 This simply adds a new method which uses the existence of a `PyVisit` object as proof that the GIL is held instead of a `Python` object. This allows `GILProtected` to be used in instances where contained Python objects need to participate in garbage collection. Usage in this situation should be valid since no Python calls are made and this does not provide any additional mechanism for accessing a `Python` object.
4e8b881
to
3249feb
Compare
Good catch. Done! |
CodSpeed Performance ReportMerging #3616 will improve performances by 22.03%Comparing Summary
Benchmarks breakdown
|
Closes #3615
This simply adds a new method which uses the existence of a
PyVisit
object as proof that the GIL is held instead of aPython
object. This allowsGILProtected
to be used in instances where contained Python objects need to participate in garbage collection. Usage in this situation should be valid since no Python calls are made and this does not provide any additional mechanism for accessing aPython
object.