-
Notifications
You must be signed in to change notification settings - Fork 190
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
Make GC more thread-safe #883
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #883 +/- ##
==========================================
- Coverage 67.61% 67.54% -0.08%
==========================================
Files 20 20
Lines 1967 1981 +14
==========================================
+ Hits 1330 1338 +8
- Misses 637 643 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
See my comment here: #882 (comment) I think we probably need to copy the FFTW.jl solution here, which was rather painfully developed with the help of @vtjnash. (I wonder if we should refactor that solution out into a package so that both FFTW.jl and PyCall.jl can use the same code? The logic is pretty subtle to get right. Maybe put the package in https://github.com/JuliaParallel?) |
Hmm, I'm not sure we can factor the FFTW.jl solution that cleanly into a package, since |
Reading the Python documentation some more, it seems like the solution may be simpler — we're not really allowed to call Python from anything other than the main thread unless we do a lot more work, so if |
Yea youre right, I'm showing some of my ignorance on this stuff here. Re: the last comment, I think I see your point and maybe a simple way to do it, also basically amounts (I think) to option two from that Julia doc link instead of option 3. Will give it a go. |
bdc0edf
to
dcbc9ee
Compare
Ok, this is quite simple and seems to work. |
Actually, sorry, I realize this doesn't actually solve the segfault I was seeing in #881 (comment). I was getting confused since that only happens on this one system. So fwiw, I don't have an evironment where this PR fixes anything, either its not needed, or I get those segfaults regardless 🤷 granted it seems like a right thing to do. |
Is it sufficient to guarantee that In JavaCall.jl, this is a necessary condition for some operations due to how Julia addresses the stack for each |
Fixed the return value. Up to you to decide what to do with this PR. Personally I'm far from sure on what the right solution is, if one is needed at the moment at all . |
What does PythonCall.jl do, @cjdoris? |
All the finalisers in PythonCall go via These functions either immediately decref the pointer, or add it to a list of pointers to decref later. However, this is currently purely controlled by explicit |
@marius311, is there any update on whether this PR observably fixes anything? I'm guessing that it may be more crucial now that Julia's GC is multi-threaded (JuliaLang/julia#48600) in Julia 1.10. |
I've been seeing a lot more segfaults on recent Julia + Python versions (x-ref #1072) so I was wondering if I could help revive this PR – @marius311 are you up for rebasing this and getting it ready for some new reviews? |
I also think even though this PR might not be the optimal GC strategy, at least it's safe. We can always improve it later. |
btw I have a similar PR for PythonCall here: JuliaPy/PythonCall.jl#520. My version is a bit more complicated as I'm using a dedicated task on thread 1 to process the GC queue (and some of the complication is just around testing that it's working properly, and since PythonCall has enable/disable functionality for it's GC). |
Here's my maybe naive way to fix #882.
Trying to aquire the GIL from the finalizer led to deadlocks. This is instead basically option 3 from here. Tests pass locally and this fixes the original issue, but I'm not an expert so maybe this has other consequences I'm not thinking of. Comments welcome.