Skip to content

[BUG] pybind11::cast is not thread safe #2765

Open
@zachariahreed

Description

@zachariahreed

in particular use of loader_life_support seems problematic. This function keeps state in the global loader_patient_stack:

std::vector<PyObject *> loader_patient_stack; // Used by `loader_life_support`
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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcastersRelated to casters, and to be taken into account when analyzing/reworking castershelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions