JuliaPy / JuliaPy/PyCall.jl

thread safety

オープン
#882 コメント 30 件 リアクション 1 件 担当者 0 名 GitHub で見る
bug
主要言語
Julia
スター
1.5k
フォーク
186
PR マージ指標
30日以内にマージされた PR はありません

説明

If Julia's `Threads.nthreads() > 1`, we may want to do some more work to ensure thread safety. In particular:

* Call `PyEval_InitThreads()` in `__init__` (this is only needed for Python ≤ 3.6, and is a no-op in Python ≥ 3.7).
* Acquire the GIL in the PyObject `finalizer`, by calling `PyGILState_Ensure` (returns an [`enum`](https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Include/pystate.h#L95-L96), i.e. a `Cint` in Julia) and `PyGILState_Release`. This is because the Julia GC may be called from threads other than the main thread, so we need to ensure that we hold Python's GIL before decref-ing.

We might also expose an API to acquire the GIL, but in general I would recommend that user code should only call Python from the main thread.

See [this forum post](https://discourse.julialang.org/t/help-with-pycall-related-segfault/55998?u=stevengj) and #881 for a possible test case.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず package __init__ パスと PyObject ファイナライザを調査し、次に #881 で参照されている可能性のあるテストケースを確認します。スレッドの初期化に関する Python バージョンの挙動と、Julia GC がメインスレッド以外からファイナライザを実行する場合について確認します。関連するスレッドセーフティのケースで、GIL なしに Python API 呼び出しが行われるリスクがなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia, python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。