Skip to content

IO from python-spawned threads causes deadlocks #540

Open
@lassepe

Description

@lassepe

Description

Carrying over from #539

The following code reaches a deadlock:

from concurrent.futures import ThreadPoolExecutor, as_completed
from juliacall import Main as jl

jl.seval(
    """
function my_sqr()
    println("Julia get's stuck at this print statement issued from thread $(Threads.threadid())")
    a = rand(10)
    for ii in 1:size(a, 1)
        a[ii] = a[ii]^2
    end
    return sum(a)
end
"""
)

pool = ThreadPoolExecutor(2)

fs = {pool.submit(jl.my_sqr): ix for ix in range(10)}
for future in as_completed(fs):
    print("running")
    rank = fs[future]
    results = future.result()
    print("done")
    print(results)

Potential Fix

Adding ccall(:jl_enter_threaded_region, Cvoid, ()) as suggested in #539 (comment) fixes this issue but not the original one of #539.
PythonCall may consider to invoke jl_enter_threaded_region behind the scenes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions