[Python] embedding python in multi threaded c++ environment

Discussão em 'Python' iniciado por Stack, Junho 30, 2025.

  1. Stack

    Stack Membro Participativo

    • python 3.13.5
    • windows 10
    • msvc

    This is how initialize python in main.

    Py_InitializeEx(0);
    PyEval_InitThreads();
    if (!Py_IsInitialized()) {
    std::cerr << "Python failed to initialize\n";
    return 1;
    }


    Python is getting properly initialized after this.

    I am using multi threaded framework taskflow which is calling this compute function in which I am doing python related stuff.

    void PyTask::compute() {
    PyGILState_STATE gstate = PyGILState_Ensure();


    This line is crashing the app. Wrapping up this into try-catch also not helping in order to trace the cause. I have found this article which is related to my problem but it's pretty old and for python 2.x. I am not sure still it's valid or not.

    Continue reading...

Compartilhe esta Página