diff --git a/nifi-docs/src/main/asciidoc/python-developer-guide.adoc b/nifi-docs/src/main/asciidoc/python-developer-guide.adoc index 0bfd4368bdc4..10cca61a7253 100644 --- a/nifi-docs/src/main/asciidoc/python-developer-guide.adoc +++ b/nifi-docs/src/main/asciidoc/python-developer-guide.adoc @@ -324,8 +324,10 @@ created in the Processor's Python code. `attributes` and `contents` are both opt the FlowFile will still have the usual `filename`, `path` and `uuid` attributes, but no additional ones. If `contents` is not provided, a FlowFile with no contents (only attributes) will be created. In case there is no useful information to return from the `create` method, `return None` can be used instead of returning an -empty `FlowFileSourceResult`. When `create` returns with `None`, the processor does not produce any output. - +empty `FlowFileSourceResult`. When `create()` returns with `None`, the processor does not produce any output. +When there is nothing to return, it might be useful to yield the processor's resources and not schedule the processor +to run for the period of time defined by the processor's Yield Duration. This can be achieved by calling +`context.yield_resources()` from the processor's `create` method right before returning `None`. [[property-descriptors]] diff --git a/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-extension-api/src/main/python/src/nifiapi/properties.py b/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-extension-api/src/main/python/src/nifiapi/properties.py index a37107ac1881..a316223f22eb 100644 --- a/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-extension-api/src/main/python/src/nifiapi/properties.py +++ b/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-extension-api/src/main/python/src/nifiapi/properties.py @@ -346,6 +346,9 @@ def __init__(self, java_context): def getName(self): return self.name + def yield_resources(self): + JvmHolder.java_gateway.get_method(self.java_context, "yield")() + class ValidationContext(PropertyContext): diff --git a/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-framework/src/main/python/framework/Controller.py b/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-framework/src/main/python/framework/Controller.py index 2057fb54a3c6..3fab4a8d9888 100644 --- a/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-framework/src/main/python/framework/Controller.py +++ b/nifi-framework-bundle/nifi-framework-extensions/nifi-py4j-framework-bundle/nifi-python-framework/src/main/python/framework/Controller.py @@ -17,6 +17,7 @@ import os import sys from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor +from py4j import java_gateway from py4j.java_gateway import JavaGateway, CallbackServerParameters, GatewayParameters import ExtensionManager @@ -122,6 +123,7 @@ class Java: from nifiapi.__jvm__ import JvmHolder JvmHolder.jvm = gateway.jvm JvmHolder.gateway = gateway + JvmHolder.java_gateway = java_gateway # We need to import PythonProcessorAdapter but cannot import it at the top of the class because we must first initialize the Gateway, # since there are statically defined objects in the file that contains PythonProcessorAdapter, and those statically defined objects require the Gateway.