Crash with Python 3.12+ When Using Concurrent Threads

Đang mở
#1,057 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, python
Lĩnh vực
desktop

Hướng nghiên cứu

Bắt đầu với tệp đính kèm TestQtBoostPython312.zip và tái hiện sự cố crash bằng cách thực thi Py_Initialize() trên một thread và các lệnh gọi Boost.Python trên một thread khác, đồng thời so sánh Python 3.11 và 3.12. Kiểm tra đường dẫn khởi tạo và thực thi liên quan đến thread; công việc được xem là hoàn tất khi nguyên nhân được xác định và hành vi tương thích hoặc bản sửa lỗi cần thiết được ghi lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
HTML
Star
8.6k
Fork
2k
Merge trung bình
9 giờ 35 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/boost

Tất cả issue của boostorg/boost

Issue tương tự

Thêm issue về Desktop Dev

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.