Crash with Python 3.12+ When Using Concurrent Threads

オープン
#1,057 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp, python
領域
desktop

調査の方向性

添付されたTestQtBoostPython312.zipから始め、1つのスレッドでPy_Initialize()を実行し、別のスレッドでBoost.Pythonの呼び出しを実行してクラッシュを再現し、Python 3.11と3.12を比較します。スレッドに関連する初期化および実行パスを調査します。原因が特定され、互換性のある動作または必要な修正が文書化されれば完了です。

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

説明

Hi, I have a Windows application that has been using Boost Python for many years now, and we are looking to upgrade from Python 3.7 to Python 3.12. This is a C++ application written in Qt5 that uses Boost Python to interface with Python scripts that do some scientific calculations, and the results are displayed in the C++ application. As such, these calculations are by and large done on a concurrent thread so as not to block the UI; however, some quick python functions are run from the main thread.

The problem is that something changed in the Python 3.12 upgrade, and I'm not sure what -- but now it crashes when I run Python code from a different thread from the one I called Py_Initialize() on. I've tested up to Python 3.11, and I can Py_Initialize() on the main thread and call Python code from any thread and everything works. But starting in Python 3.12, that's no longer the case. If I initialize Python on the UI thread, I can only run it from that thread. If I initialize it on a concurrent thread, I can only run it on a concurrent thread.

Since I am using Python, Qt5, and Boost Python, I am not 100% sure where the fault lies, but I posted to the Python github and they suggested I post here as well.

I have attached a minimal example project in case that's helpful for debugging: TestQtBoostPython312.zip

Essentially, this is the meat of my code:

//Initialization Function:

Py_Initialize();

//Boost Python Code:

boost::python::object main = boost::python::import("__main__");
boost::python::object name_space(main.attr("__dict__"));
boost::python::exec_file("testPython.py", name_space, name_space);
double testNumber = boost::python::extract<double>(name_space["testNumber"]);
qDebug() << testNumber; //print(testNumber)

#testPython.py:

import random
testNumber = random.random()

Thanks for any help you can provide.

主要言語
HTML
スター
8.6k
フォーク
2k
平均マージ
9時間 35分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/boost のほかの issue

boostorg/boost の issue をすべて見る

似ている issue

Desktop Dev の issue をもっと見る

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

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