martinzink commented on code in PR #1504:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1504#discussion_r1126761844


##########
extensions/python/PythonScriptEngine.cpp:
##########
@@ -0,0 +1,183 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+#include <filesystem>
+
+#include "PythonScriptEngine.h"
+#include "PythonBindings.h"
+#include "types/PyProcessSession.h"
+#include "types/PyProcessContext.h"
+#include "types/PyProcessor.h"
+#include "types/PyLogger.h"
+#include "types/PyRelationship.h"
+
+namespace org::apache::nifi::minifi::extensions::python {
+
+Interpreter* Interpreter::getInterpreter() {
+  static Interpreter interpreter;
+  return &interpreter;
+}
+
+GlobalInterpreterLock::GlobalInterpreterLock() {
+  gil_state_ = PyGILState_Ensure();
+}
+
+GlobalInterpreterLock::~GlobalInterpreterLock() {
+  PyGILState_Release(gil_state_);
+}
+
+namespace {
+// PyEval_InitThreads might be marked deprecated (depending on the version of 
Python.h)
+// Python <= 3.6: This needs to be called manually after Py_Initialize to 
initialize threads
+// Python >= 3.7: Noop function since its functionality is included in 
Py_Initialize
+// Python >= 3.9: Marked as deprecated (still noop)
+// This can be removed if we drop the support for Python 3.6
+void initThreads() {
+#if defined(__clang__)
+  #pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#elif defined(WIN32)
+  #pragma warning(push)
+#pragma warning(disable: 4996)
+#endif

Review Comment:
   I'm not sure if I follow, but we want to include the `PyEval_InitThreads` no 
matter the python version of the build environment because we want it to be 
called when used with 3.6 python. I simply wanted to silence the warnings if 
the build environment is above 3.9.



-- 
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]

Reply via email to