Running scripts with the Scripting pane
You can run scripts using the Scripting pane in Synthetic Data Generator.
About this task
You can add and modify scripts in the Scripting pane, and then you can run the flow script at the same time that the flow runs. The following examples show some simple scripts that you can run.
One of the methods that's defined for a flow is runAll(List). This method runs all executable nodes. Any outputs that are generated by running the nodes are added to the supplied list. The following example runs all executable nodes
in the flow, and is the simplest type of flow script:
sdg.script.stream().runAll(None)
The following example also runs all executable nodes in the flow by using a variable:
stream = sdg..script.stream()
stream.runAll(None)
The flow is stored in a variable called stream. Storing the flow in a variable is useful because a script is typically used to modify either the flow or the nodes within a flow. Creating a variable that stores the flow results in a more concise script.
Procedure
-
On the toolbar, click the Scripting icon
.
The Scripting pane opens. Use it to work with flow scripts for the current flow.
-
Add the flow script that you want.
-
Run the script in one of the following ways:
- To run the script when the flow runs, toggle Run script with flow to on and click Run flow on the toolbar.
- To run only the script, follow these additional steps:
-
Add the following line to your script to run all the nodes in the flow as part of the script.
sdg.script.stream().runAll(None) -
Toggle Run script with flow to on and click Run selected on the toolbar.
-
Interrupting a running script
Within the Scripting pane pane, the red stop button is activated when a script is running. Use this button if you need to stop running the script and any current flow.
The sdg.script module also defines a way of terminating the script with an exit code. The exit(exit-code) function stops the script from running and returns the supplied integer exit code.