Skip to content

julia thread hangs with multiple sevals #202

Closed
@dpinol

Description

@dpinol

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

from juliacall import Main as jl

jl.seval(
    """
    function worker()
            for i in 1:typemax(Int64)
                a = Float64[]
                push!(a, 0.42)
                i % 1000 == 0 && println(i)
            end
    end
"""
)
jl.seval(
    """
begin
#println(42) #this fixes hang only on 1.8rc1
t = Threads.@spawn worker()
println("waiting")
wait(t)
end
"""
)

On my computer it hangs after printing 30200

....
301000
302000

The code runs fine also with a single eval

from juliacall import Main as jl

jl.seval(
    """
begin
    function worker()
            for i in 1:typemax(Int64)
                a = Float64[]
                push!(a, 0.42)
                i % 1000 == 0 && println(i)
            end
    end

#println(4) #this fixes hang only on 1.8rc1
t = Threads.@spawn worker()
println("waiting")
wait(t)
end
"""
)

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions