8000 Static PyArray_typeinfoType* breaks sub-interpreter numpy load · Issue #18586 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Static PyArray_typeinfoType* breaks sub-interpreter numpy load #18586
Open
@basilgello

Description

@basilgello

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:

  1. Install Kodi from Arch Linux or Kodi from Debian cleanly
  2. Add jurialmunkey's plugin.video.themoviedb.helper
  3. 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:

static PyTypeObject PyArray_typeinfoType;

Running the following GDB script:
numpy.gdb.txt
illustrates the issue:
gdb.log.txt

  1. Here in gdb.log.txt, "Thread 34" is the first sub-interpreter thread that performs NumPy import.
  2. Then, a new sub-interpreter is kicked in "Thread 56".
  3. Since "Thread 56" has no numpy variable declared in its scope, the re-import occurs.
  4. The following code returns -1:

if (PyStructSequence_InitType2(

and the ../Objects/structseq.c:401: bad argument to internal function',) exception is thrown.

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EmbeddedIssues regarding embedded python interpreters

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0