[PyOV] Accept Python functions as Extension attrs and properly capture GIL (#18992)
This commit is contained in:
parent
ef6c8c1d66
commit
baa0ce46b0
@ -26,6 +26,26 @@ void regclass_frontend_TelemetryExtension(py::module m) {
|
||||
"TelemetryExtension",
|
||||
py::dynamic_attr());
|
||||
|
||||
ext.def(py::init([](const std::string& event_category,
|
||||
py::function& send_event,
|
||||
py::function& send_error,
|
||||
py::function& send_stack_trace) {
|
||||
return std::make_shared<TelemetryExtension>(
|
||||
event_category,
|
||||
[send_event](const std::string& category, const std::string& action, const std::string& label, int value) {
|
||||
py::gil_scoped_acquire acquire;
|
||||
send_event(category, action, label, value);
|
||||
},
|
||||
[send_error](const std::string& category, const std::string& error_message) {
|
||||
py::gil_scoped_acquire acquire;
|
||||
send_error(category, error_message);
|
||||
},
|
||||
[send_stack_trace](const std::string& category, const std::string& error_message) {
|
||||
py::gil_scoped_acquire acquire;
|
||||
send_stack_trace(category, error_message);
|
||||
});
|
||||
}));
|
||||
|
||||
ext.def(py::init([](const std::string& event_category,
|
||||
const TelemetryExtension::event_callback& send_event,
|
||||
const TelemetryExtension::error_callback& send_error,
|
||||
@ -96,6 +116,13 @@ void regclass_frontend_ProgressReporterExtension(py::module m) {
|
||||
return std::make_shared<ProgressReporterExtension>();
|
||||
}));
|
||||
|
||||
ext.def(py::init([](py::function& callback) {
|
||||
return std::make_shared<ProgressReporterExtension>([callback](float a, unsigned int b, unsigned int c) {
|
||||
py::gil_scoped_acquire acquire;
|
||||
callback(a, b, c);
|
||||
});
|
||||
}));
|
||||
|
||||
ext.def(py::init([](const ProgressReporterExtension::progress_notifier_callback& callback) {
|
||||
return std::make_shared<ProgressReporterExtension>(callback);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user