`vtkpython -h` raises exception when VTK is compiled with `VTK_PYTHON_FULL_THREADSAFE`
Compiling a recent vtk (6801d027) with python enabled and VTK_PYTHON_FULL_THREADSAFE=ON
causes vtkpython
to fail when an argument is passed like for example vtkpython -h
or --version
.
Below the result of vtkpython --help
Python 3.10.10
...
PYTHONDEVMODE: enable the development mode.
PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.
PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.
Fatal Python error: PyEval_SaveThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: preinitialized
Loguru caught a signal: SIGABRT
Stack trace:
11 0x5569a4b3d45e ./bin/vtkpython(+0x145e) [0x5569a4b3d45e]
10 0x7fcefd561083 __libc_start_main + 243
9 0x5569a4b3d2df ./bin/vtkpython(+0x12df) [0x5569a4b3d2df]
8 0x7fcefd536807 vtkPythonInterpreter::PyMain(int, char**) + 695
7 0x7fcefd53600e vtkPythonInterpreter::InitializeWithArgs(int, int, char**) + 1150
6 0x7fcefcbe76f6 /lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1e16f6) [0x7fcefcbe76f6]
5 0x7fcefcbe7ce6 /lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1e1ce6) [0x7fcefcbe7ce6]
4 0x7fcefcba3969 /lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x19d969) [0x7fcefcba3969]
3 0x7fcefca76caf /lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x70caf) [0x7fcefca76caf]
2 0x7fcefd55f859 abort + 299
1 0x7fcefd58000b gsignal + 203
0 0x7fcefd580090 /lib/x86_64-linux-gnu/libc.so.6(+0x43090) [0x7fcefd580090]
( 0.001s) [main thread ] :0 FATL| Signal: SIGABRT
Aborted (core dumped)
python 3.9.16 exhibits the same issue.
The signal comes from:
Program received signal SIGABRT, Aborted.
0x00007ffff7dfa00b in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff7dfa00b in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff7dd9859 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff72f0caf in ?? () from /lib/x86_64-linux-gnu/libpython3.10.so.1.0
#3 0x00007ffff741d969 in _Py_FatalErrorFunc () from /lib/x86_64-linux-gnu/libpython3.10.so.1.0
#4 0x00007ffff7461ce6 in _Py_FatalError_TstateNULL () from /lib/x86_64-linux-gnu/libpython3.10.so.1.0
#5 0x00007ffff74616f6 in PyEval_SaveThread () from /lib/x86_64-linux-gnu/libpython3.10.so.1.0
#6 0x00007ffff7db000e in vtkPythonInterpreter::InitializeWithArgs (initsigs=1, argc=2, argv=0x555555580000) at ../vtk/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx:344
#7 0x00007ffff7db0807 in vtkPythonInterpreter::PyMain (argc=<optimized out>, argv=<optimized out>) at ../vtk/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx:595
#8 0x00005555555552df in main (argc=2, argv=0x7fffffffdba8) at ../vtk/Wrapping/Python/vtkPythonAppInit.cxx:119
which points to https://gitlab.kitware.com/vtk/vtk/-/blob/master/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx#L344
for python 3.8.10 the issue is similar but the signal comes from PyEval_InitThreads()
a few lines above.