Menu

Running script after thread termination

Help
2016-06-16
2016-06-16
  • Alexander Kosik

    Alexander Kosik - 2016-06-16

    Hello.

    We run python scripts in a separate thread to avoid any blockings of our GUI.
    If we want to stop the execution the thread is terminated (QThread::terminate()).
    This termination works - in most cases.

    It will not work if we execute a script with a blocking python operation. For example a script like this:

    import time
    time.sleep(30)
    

    In this case the next execution of PythonQt::createUniqueModule or PythonQt::evalScript will crash in python35.dll with the following message:

    Py_FatalError("PyThreadState_Get: no current thread");
    

    The call stack looks like this:

    python35_d.dll!Py_FatalError(const char * msg)  Zeile 1387  C
    python35_d.dll!PyThreadState_Get()  Zeile 499   C
    python35_d.dll!PyErr_Fetch(_object * * p_type, _object * * p_value, _object * * p_traceback)  Zeile 337 + 0x5 Bytes
    python35_d.dll!_Py_PrintFatalError(int fd)  Zeile 1276  C
    python35_d.dll!Py_FatalError(const char * msg)  Zeile 1362  C
    python35_d.dll!PyThreadState_Get()  Zeile 499   C
    python35_d.dll!PyErr_Restore(_object * type, _object * value, _object * traceback)  Zeile 30 + 0x5 Bytes    C
    python35_d.dll!PyErr_Clear()  Zeile 352 C
    PythonQt.dll!PythonQt::createModuleFromScript(const QString & name, const QString & script)  Zeile 910  C++
    PythonQt.dll!PythonQt::createUniqueModule()  Zeile 925 + 0x39 Bytes C++
    

    I understand that the behaviour after a thread termination may be undefined and that the python35.dll will not work correctly after its execution thread was terminated.

    What we need is a way to reinitialize PythonQt and the python35.dll.

    Calling

    PythonQt::cleanup();
    PythonQt::init();
    

    after thread termination is not sufficient. It will still crash.

    Is there a way to reinitialize PythonQt completly? If so, how does it work?
    Or are there any other ways of terminating a blocking operation, maybe some kind of "soft kills"?

    Any advice is appreciated.

     
  • Florian Link

    Florian Link - 2016-06-16

    Sorry, I have no idea how that could be done. QThread::terminate is surely something you should avoid.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.