<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I have seen several fixes for Python 3.7, but have been tracking down why Tomviz deadlocks on when using vtkPythonScopeGilEnsurer, and it appears to be related to the Python specific flags we are using and a behavior change in Python 3.7. This may mainly be a question for David Gobbi and/or Utkarsh. but I send it to the list so that others have a chance to see it, and it gets indexed should others hit this issue.</div><div><br></div><div>We use VTK_PYTHON_FULL_THREADSAFE set to ON, and VTK_NO_PYTHON_THREADS set to OFF. This means that when vtkPythonInterpreter::Initialize is called that the following code will be called:</div><div><br></div><div><div>#ifdef VTK_PYTHON_FULL_THREADSAFE</div><div>    int threadInit = PyEval_ThreadsInitialized();</div><div>    PyEval_InitThreads(); // safe to call this multiple time</div><div>    if (!threadInit)</div><div>    {</div><div>      PyEval_SaveThread(); // release GIL</div><div>    }</div><div>#endif</div></div><div><br></div><div>This was effectively always calling PyEval_SaveThread() before Python 3.7. but this is now never being called as starting with Python 3.7 Py_Initialize will initialize the GIL, see <a href="https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads">https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads</a> for details.</div><div><br></div><div>It looks like this check was done to ensure that PyEval_SaveThread would only be called once, now that PyEval_InitThreads doesn't need to be called, moving PyEval_SaveThread outside of the conditional gets rid of the deadlock for me. It looks like something needs to be changed for 3.7+, but I am not clear on how necessary this logic is.</div><div><br></div><div>This reminds me that VTK_PYTHON_FULL_THREADSAFE is used in VTK, but the CMake option is in ParaView only as far as I can see. Should that be moved down into VTK, it seems odd.</div><div><br></div><div>Thanks,</div><div><br></div><div>Marcus</div></div></div></div></div></div></div></div></div></div></div>