lordgamez commented on code in PR #1712:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1712#discussion_r1507614295
##########
extensions/python/ExecutePythonProcessor.cpp:
##########
@@ -44,8 +45,7 @@ void ExecutePythonProcessor::initialize() {
try {
loadScript();
- } catch(const std::runtime_error&) {
- logger_->log_warn("Could not load python script while initializing. In
case of non-native python processor this is normal and will be done in the
schedule phase.");
+ } catch(const std::runtime_error& err) {
Review Comment:
Updated in 6d382e80a43d2c4de48091dff2e91e7b951edfb1
##########
extensions/python/PythonScriptEngine.cpp:
##########
@@ -180,4 +198,66 @@ void PythonScriptEngine::evaluateModuleImports() {
}
}
+void PythonScriptEngine::initializeProcessorObject(const std::string&
python_class_name) {
+ GlobalInterpreterLock gil;
+ if (auto python_class = bindings_[python_class_name]) {
+ auto num_args = [&]() -> size_t {
+ auto class_init =
OwnedObject(PyObject_GetAttrString(python_class->get(), "__init__"));
+ if (!class_init.get()) {
+ return 0;
+ }
+
+ auto inspect_module = OwnedObject(PyImport_ImportModule("inspect"));
+ if (!inspect_module.get()) {
+ return 0;
+ }
+
+ auto inspect_args =
OwnedObject(PyObject_CallMethod(inspect_module.get(), "getfullargspec", "O",
class_init.get()));
+ if (!inspect_args.get()) {
+ return 0;
+ }
+
+ auto arg_list = OwnedObject(PyObject_GetAttrString(inspect_args.get(),
"args"));
+ if (!arg_list.get()) {
+ return 0;
+ }
+
+ return PyList_Size(arg_list.get());
+ }();
+
+ if (num_args > 1) {
+ auto kwargs = OwnedDict::create();
+ auto value = OwnedObject(Py_None);
+ kwargs.put("jvm", value);
+ auto args = OwnedObject(PyTuple_New(0));
+ processor_instance_ = OwnedObject(PyObject_Call(python_class->get(),
args.get(), kwargs.get()));
+ } else {
+ processor_instance_ =
OwnedObject(PyObject_CallObject(python_class->get(), nullptr));
+ }
+
+ if (processor_instance_.get() == nullptr) {
+ throw PythonScriptException(PyException().what());
+ }
+
+ auto result = PyObject_SetAttrString(processor_instance_.get(), "logger",
bindings_[std::string("log")]->get());
Review Comment:
Good point about the interface, it should definitely be changed. Currently
the issue is due to this ambiguity build error:
```
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonScriptEngine.cpp:242:88:
error: ambiguous overload for ‘operator[]’ (operand types are
‘org::apache::nifi::minifi::extensions::python::OwnedDict’ {aka
‘org::apache::nifi::minifi::extensions::python::Dict<org::apache::nifi::minifi::extensions::python::ReferenceType::OWNED>’}
and ‘const char [4]’)
242 | auto result = PyObject_SetAttrString(processor_instance_.get(),
"logger", bindings_["log"]->get());
|
^
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonScriptEngine.cpp:242:88:
note: candidate: ‘operator[](long int, const char*)’ (built-in)
In file included from
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonBindings.h:24,
from
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonScriptEngine.h:20,
from
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonScriptEngine.cpp:21:
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/types/Types.h:290:36:
note: candidate:
‘std::optional<org::apache::nifi::minifi::extensions::python::ObjectReference<org::apache::nifi::minifi::extensions::python::ReferenceType::BORROWED>
>
org::apache::nifi::minifi::extensions::python::Dict<reference_type>::operator[](std::string_view)
[with org::apache::nifi::minifi::extensions::python::ReferenceType
reference_type =
org::apache::nifi::minifi::extensions::python::ReferenceType::OWNED;
std::string_view = std::basic_string_view<char>]’
290 | std::optional<BorrowedReference> operator[](std::string_view key) {
| ^~~~~~~~
/home/ggyimesi/projects/nifi-minifi-cpp-fork/extensions/python/PythonScriptEngine.cpp:246:88:
error: ambiguous overload for ‘operator[]’ (operand types are
‘org::apache::nifi::minifi::extensions::python::OwnedDict’ {aka
‘org::apache::nifi::minifi::extensions::python::Dict<org::apache::nifi::minifi::extensions::python::ReferenceType::OWNED>’}
and ‘const char [12]’)
```
It doesn't need to be `std::string` but it still needs to explicitly define
the parameter type due to this. I changed it to std::string_view which is the
expected type currently in 6d382e80a43d2c4de48091dff2e91e7b951edfb1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]