Use the Python Instance operator to specify and configure the name and features of a constrained local instance execution environment for a set of Python operators. It is the Python operator itself that executes Python code. This Python Instance operator's only purpose is to define an optional local execution environment for one or more Python operators.
Use the following steps:
-
Place a Python Instance operator on the EventFlow canvas, and give the operator a name, such as
ThisInstance
. -
In the Properties view for the Python Instance operator, select
Local
in the Instance Type control. -
Specify the full path to your preferred Python version in the Executable control.
To avoid typing the same path in several Python Instance operators, you can optionally use an operator parameter to specify the Python path. In this case, define the operator parameter in the project's
sbd.sbconf
file, in the<operator-parameters>
element. -
Next, in the Properties view for any actual Python operator:
-
Select
Local
in the Instance Type control. -
Specify the name you chose in step 1 in the Local Instance Id control.
-
By default, Python operators execute in the global execution environment of the containing EventFlow module.
However, it is possible to use EventFlow concurrency features to run multiple copies of a single module that contains Python operators. In this case, you can use a Python Instance operator to define and name a local execution environment for the Python operators in that concurrent module. In this way, the execution of Python in one concurrent instance of that module does not interfere with other instances.
You can also configure a Python Instance operator with a control port that lets you enable and disable at runtime the execution of Python operators configured to use that Python instance.
This section describes the properties you can set for the Python Instance operator, using the various tabs of the Properties view in StreamBase Studio.
Name: Use this required field to specify or change the name of this instance of this component, which must be unique in the current EventFlow module. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.
Operator: A read-only field that shows the formal name of the operator.
Start with application: If this field is set to Yes (default) or to a module parameter that evaluates to true
, this instance of this operator starts as part of the JVM engine that runs this EventFlow module. If this field is set to
No or to a module parameter that evaluates to false
, the operator instance is loaded with the engine, but does not start until you send an sbadmin resume command, or until you start the component with StreamBase Manager.
Enable Error Output Port: Select this check box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports to learn about Error Ports.
Description: Optionally enter text to briefly describe the component's purpose and function. In the EventFlow canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.
Property | Type | Description |
---|---|---|
Instance Type | radio button |
Select Local to define a constrained local Python execution environment named by the EventFlow canvas name of this operator. Select Global to disable this Python Instance's operator's local execution environment. |
Global Instance ID | drop-down list | Only active when Instance Type specifies Global. In this case, the global Python execution environment is defined in this module's configuration file. Use the drop-down control to select the name of a global instance defined in configuration. |
executable | string | Specifies the full path to the Python executable to use for all Python operators in the local execution environment defined
by this Python Instance operator. If not specified, the operator invokes the command python, which is assumed to be on the PATH. The path can be specified in ${param} form as the name of an operator parameter that specifies the Python path.
Be careful about specifying a different Python executable in this field than the executable you specify in the configuration file for the global environment — unless you explicitly intend to use a different Python version for the global and local cases. For the same reason, be careful about leaving this field blank, which then specifies the first command named python on the PATH. See Python Versions Supported for example paths. |
Working Directory | text | Applies when | is to specify the working directory for the launched Python processes in this local execution environment. If not specified, processes are started in the same directory as the parent StreamBase process.
Use Temp File | check box | Applies when NoteYou must set this property to |
is to indicate that the Python operator's integration layer should create a temporary file with Python code wrapping the interactions
with StreamBase instead of pushing it through standard input. The default standard input method works for most Python interpreters
and is the default.
Capture Output | check box | When Instance Type is Local, modifies the stdout and stderr behavior. By default, both are chained to the parent process's stdout and stderr. When running tests that include output, you can set this flag to capture the output. |
Enable Control Port | check box | Enables the control port to allow commands to be sent to this operator. See Control Port below. |
Log Level | INFO | Controls the level of verbosity the adapter uses to issue informational traces to the console. This setting is independent of the containing application's overall log level. Available values, in increasing order of verbosity, are: OFF, ERROR, WARN, INFO, DEBUG, TRACE. |
Use this tab to specify arguments to be passed to the Python interpreter (not the Python script) to be invoked for all Python operators in the local execution environment defined by this Instance operator.
The usual use for this tab it to pass -u
, which forces Python to use unbuffered stdin, stdout, and stderr streams. Consult the following references for information
on Python launch parameters:
Use this tab to specify environment variables to be passed before launching the Python interpreter by all Python operators in the local execution environment defined by this Instance operator. Environment variables specified here can potentially override variables in the platform's environment.
If you enable the control port, it accepts a tuple with any structure, but one string field must be named command. The command strings accepted on this control port are:
-
start — Enables the local Python execution environment defined by this Python Instance operator.
-
stop — Disables this operator's local Python execution environment. Any Python operators configured to use this operator's instance return an error instead of processing input tuples while this Python Instance operator is disabled.
Any unrecognized fields in the control port's input tuple are ignored.