Turn calls of __traverse__ into no-ops for unsendable pyclass if on the wrong thread#3689
Conversation
d14e3b8 to
8ef1d1e
Compare
CodSpeed Performance ReportMerging #3689 will not alter performanceComparing 🎉 Hooray!
|
|
@JRRudy1 Could you use a dependency specification like pyo3 = { git = "https://github.com/PyO3/pyo3.git", branch = "unsendable-threadsafe-traverse" }and verify that this would work for your use case? Thanks. |
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, nice! Looks straightforward enough.
I wonder if there's a way to add a test for this. I suspect the most reasonable option, if we felt it worth it, would be to add a test which manually calls the traverse slot?
Will give it a try. I also noticed that this should be mentioned in the guide... |
2f37419 to
0435ce0
Compare
davidhewitt
left a comment
There was a problem hiding this comment.
Looks great to me, thanks, great test 👍
…he wrong thread Adds a "threadsafe" variant of `PyCell::try_borrow` which will fail instead of panicking if called on the wrong thread and use it in `call_traverse` to turn GC traversals of unsendable pyclasses into no-ops if on the wrong thread. This can imply leaking the underlying resource if the originator thread has already exited so that the GC will never run there again, but it does avoid hard aborts as we cannot raise an exception from within `call_traverse`.
0435ce0 to
4dc6c16
Compare
Adds a "threadsafe" variant of
PyCell::try_borrowwhich will fail instead of panicking if called on the wrong thread and use it incall_traverseto turn GC traversals of unsendable pyclasses into no-ops if on the wrong thread.This can imply leaking the underlying resource if the originator thread has already exited so that the GC will never run there again, but it does avoid hard aborts as we cannot raise an exception from within
call_traverse.Closes #3688