Description
I found this issue to be a root cause of:
xbmc/xbmc#19324
jurialmunkey/plugin.video.themoviedb.helper#445
python-pillow/Pillow#5320
Steps to reproduce:
- Install Kodi from Arch Linux or Kodi from Debian cleanly
- Add jurialmunkey's plugin.video.themoviedb.helper
- Try starting an addon and experience Kodi segfault
Error message:
The error message is quite obscure at a first glance:
xbmc/xbmc#19324 (comment)
xbmc/xbmc#19324 (comment)
but digging it here revealed that the issue is the static members:
Running the following GDB script:
numpy.gdb.txt
illustrates the issue:
gdb.log.txt
- Here in
gdb.log.txt
, "Thread 34" is the first sub-interpreter thread that performs NumPy import. - Then, a new sub-interpreter is kicked in "Thread 56".
- Since "Thread 56" has no
numpy
variable declared in its scope, the re-import occurs. - The following code returns -1:
numpy/numpy/core/src/multiarray/typeinfo.c
Line 116 in cb557b7
and the ../Objects/structseq.c:401: bad argument to internal function',)
exception is thrown.
- Later, the
Py_XIncRef
tries incrementing the wrong memory chunk and throws SIGSEGV.
I tried to make PyArray_typeinfoType
and PyArray_typeinforangedType
sub-intepreter compatible, but it seems all C++ modules declare module context block size as -1
,
indicating they are all not sub-interpreter compatible.
To make multiarray
sub-interpreter compatible, one needs to move all static members like PyArray_typeinfoType
into that block allocated on module definiton and ensure it gets freed on module unload.