pybind/pybind11

[BUG] pybind11::cast is not thread safe

Open

#2765 aperta il 31 dic 2020

Vedi su GitHub
 (21 commenti) (0 reazioni) (0 assegnatari)C++ (2005 fork)batch import
bugcastershelp wanted

Metriche repository

Star
 (14.677 star)
Metriche merge PR
 (Merge medio 5g 2h) (10 PR mergiate in 30 g)

Descrizione

in particular use of loader_life_support seems problematic. This function keeps state in the global loader_patient_stack: https://github.com/pybind/pybind11/blob/b7dfe5cc84ca1891b50e728e83c9b5b393cf5272/include/pybind11/detail/internals.h#L105 In the case where a cast can release the GIL, two thread's push/pop of loader_patient_stack can become interleaved.

While releasing the GIL in a conversion seems like a bad idea, it can be surprisingly hard to avoid. Any cast that results in the bytecode interpreter being run (either directly or through something like a __del__ method) can cause python itself to release GIL (sys.setswitchinterval).

Guida contributor