JuliaPy / JuliaPy/PythonCall.jl

IO from python-spawned threads causes deadlocks

未关闭
#540 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Julia
星标
1.1k
派生
86
平均合并
1 天 22 小时
30 天内合并 PR
3

描述

**Description**

Carrying over from [#539](https://github.com/JuliaPy/PythonCall.jl/issues/539#issuecomment-2293753477)

The following code reaches a deadlock:

```python
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 https://github.com/JuliaPy/PythonCall.jl/issues/539#issuecomment-2295200264 fixes this issue but not the original one of #539.
PythonCall may consider to invoke `jl_enter_threaded_region` behind the scenes.

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start by running the provided Python ThreadPoolExecutor example with juliacall and confirm where execution deadlocks. Then inspect the PythonCall path used for Python-spawned calls and the suggested jl_enter_threaded_region invocation; done means eliminating this deadlock without regressing the related behavior described in #539.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。