pybind/pybind11

Feature Request: Cancelling a Nurse/Patient Relationship for keep_alive

Open

#1,708 创建于 2019年2月22日

在 GitHub 查看
 (1 评论) (1 反应) (0 负责人)C++ (2,005 fork)batch import
enhancementhelp wanted

仓库指标

Star
 (14,677 star)
PR 合并指标
 (平均合并 5天 2小时) (30 天内合并 10 个 PR)

描述

I would like to request a feature be made that cancels the keep_alive<nurse, patient> relationship. I have found a use case for callbacks which require a way to cancel the keep_alive functionality upon a python function call bound with pybind11 (unregister_callback). Please see example below:

Example:

.def("register_callback", &registerCallback, py::keep_alive<1, 2>())
.def("unregister_callback", &unregisterCallback);

class CallBack():
    ....

def func(connection):
    callback = CallBack()
    connection.regsiter_callback(callback)
    # do something
    connection.unregister_callback(callback)

func(conn)
func(conn)
func(conn)

None of the callback objects will be destroyed until the connection object is destroyed. These callbacks could be holding resources that the user expects to be freed upon exiting func(). I would like to be able to add something to the unregister_callback pybind11 definition that would allow me to cancel keep_alive when unregister_callback is called.

贡献者指南