pybind/pybind11

[BUG] pybind11::cast is not thread safe

Open

#2,765 创建于 2020年12月31日

在 GitHub 查看
 (21 评论) (0 反应) (0 负责人)C++ (14,677 star) (2,005 fork)batch import
bugcastershelp wanted

描述

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

贡献者指南