Issue with Python 3.12 and Concurrent Threads

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 am posting this here in case anyone has run into this issue. I haven't found any other references to it online. I can post a minimal example project if that would be helpful for debugging. 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.
participants (1)
-
jholbrook@kinetic-vision.com