Acquire GIL around every Python API call - #1097
Conversation
b3aea39 to
dd3cc6d
Compare
|
Before this can be considered complete, it needs an equivalent to JuliaMath/FFTW.jl#160 to handle:
edit: Done! |
Majority of the API is covered by updating the `@pycheck(v/n)` macros. The rest is covered manually by `@with_GIL`. Care should be taken to avoid yielding to the Julia scheduler, which could cause task migration and lead to deadlocks.
a395a25 to
25038c7
Compare
This is required to avoid deadlocking in the GC as it executes finalizers.
Required to avoid starving the scheduler or deadlocking against the GC.
|
Is there any known issue with this currently? Are we going to use this approach? I've rebased this on master at https://github.com/JuliaPy/PyCall.jl/tree/ct/with-gil-rebase with a few fixes/tweaks.
One of the few issues I could think of is maybe if there are a lot of object that became garbage they can only be free'd the next time the user calls a PyCall API, which may not happen for a while. For example, the following code can place unbound number of objects in the deferred list, [PyObject(i) for i in 1:100000];Maybe the finalizer should detect some cases where the GIL is safe to acquire (e.g. try to acquire without waiting) and clear the queue? |
This should resolve #1096 by wrapping every Python API usage in a GIL acquire-release.
If this leads to overhead, we can probably re-export a "manual GIL" version of the API that allows consumers to manage the GIL themselves. In any case, it's worth having proper support for multi-threading.
Fixes #1096. Fixes #1095. Fixes #1090. Fixes #1088.
Fixes #1078. Fixes #1077. Fixes #1072. Fixes #1083.
Fixes timholy/Revise.jl#989.