-
Notifications
You must be signed in to change notification settings - Fork 66
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
julia thread hangs with multiple sevals #202
Comments
Maybe related to JuliaLang/julia#45899 ? However, I still get the hang with julia 1.8rc3 |
I don't have a Linux box, but I'm failing to reproduce your issue in a VM (WSL on Windows and Docker on Mac). Can you give me precise instructions of how you can reproduce your issue on a fresh box - what exactly do you install (versions of Python and Julia and their packages) and what commands do you run? Though TBH even if I could reproduce it I'm not sure where I'd start debugging this. It seems like an issue with task/thread scheduling, which I know very little about. |
Hi, OS:I can reproduce it both:
JuliaI can reproduce it on julia 1.7, 1.8-rc1, 1.8-rc3 and 1.9master PythonI can reproduce it on python 3.9 & 3.10 |
Ah possibly (hopefully) related to #201 then. My best guess is that since your loop is allocating, at some point GC is invoked, which triggers the finalizer of some Python object, which deadlocks the GIL lock it acquires. Support for working in a multithreaded environment should be considered experimental at best right now. |
do you mean python or Julia GC?
do you mean internal python objects? The test above does not make any communication betwen julia & python |
I mean Julia GC. Your actual code doesn't touch python, but the act of calling |
yes! In my real code, this trick solves the hang for i in 1:total
GC.enable(false)
Threads.@threads for x in list
loop(x)
end
GC.enable(true)
i % 100 == 0 && GC.gc(false)
end It's important to periodically call GC to avoid memory exhaustion (see JuliaLang/julia#45068) |
OK great. I can also reproduce the issue. Another work-around is to insert |
Over on the from juliacall import Main as jl
jl.seval(
"""
function worker()
for i in 1:10_000_000
a = Float64[]
push!(a, 0.42)
i % 1000 == 0 && println(i)
end
end
"""
)
jl.seval(
"""
begin
PythonCall.C.gc_disable()
t = Threads.@spawn worker()
println("waiting")
wait(t)
PythonCall.C.gc_enable()
end
"""
) If you want to try it out, check out the branch, copy |
I've just released a version of PythonCall with these functions, except they are now called |
hi, thanks for looking into this! |
I found a solution for a similar problem and mentioned that in #201, which is still open. |
Hi,
I can reproduce a hang (no cpu activity) with the following code on 1.8rc1, 1.8rc3 & 1.9dev.
I'm running on Ubuntu 21.10, but I can also reproduce it on Apple M1.
Curiously, but only in 1.8rc1, the hang does not occur if I uncomment the
println(42)
.I could not reproduce the hang directly on julia.
On my real code I tried merging the 2 seval calls, but it still freezes with 1.
It's very important to enable parallelism setting env vars
JULIA_NUM_THREADS=6
On my computer it hangs after printing 30200
The code runs fine also with a single eval
thanks
The text was updated successfully, but these errors were encountered: