Skip to content

[BUG]: py::py::mod_gil_not_used() maybe not support python 3.14.0 free threaded feature, when using callback function #5894

@AeloriaDev

Description

@AeloriaDev

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3.0.1

Problem description

c++ wrapper.cc

PYBIND11_MODULE(demo, m, py::mod_gil_not_used()) {
m.def(
"callback",
[](py::function cb) {
cb("aaa");
cb("bbb");

        std::future<void> f1 = std::async(std::launch::async, [cb] {
            cb("aaa");
        });
        std::future<void> f2 = std::async(std::launch::async, [cb] {
            cb("bbb");
        });
        f1.get();
        f2.get();
    },
    "Call a Python callback from C++");

}

demo.py:

def fun(a):
print("Hello", a)
import time
time.sleep(3)
print("Hello-----", a)

kcal.callback(fun)

When I run this function, the program raise "Segmentation fault (core dumped)"

Reproducible example code


Is this a regression? Put the last known working version here if it is.

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions