Crash with Python 3.12+ When Using Concurrent Threads

Abierto
#1,057 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
cpp, python
Área
desktop

Línea de trabajo

Comienza con el archivo adjunto TestQtBoostPython312.zip y reproduce el fallo ejecutando Py_Initialize() en un hilo y las llamadas de Boost.Python en otro, comparando Python 3.11 y 3.12. Inspecciona la ruta de inicialización y ejecución relacionada con los hilos; el trabajo estará terminado cuando se haya identificado la causa y se haya documentado el comportamiento compatible o la corrección necesaria.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
HTML
Estrellas
8.6k
Forks
2k
Merge medio
9 h 35 min
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de boostorg/boost

Todos los issues de boostorg/boost

Issues similares

Más issues de Desktop Dev

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.