Pipelines and Blocks - Pipeline Basics | Razor Think
Accessing and Manipulating Data

Pipelines and Blocks – Pipeline Basics

By December 11, 2020 No Comments

Pipelines and Blocks – Pipeline Basics

More articles in Accessing and Manipulating Data

  • from razor.blocks import Block, inputs, outputs from razor.blocks import SocketTransport from razor.blocks import ThreadExecutor, ProcessExecutor from razor.pipeline import Pipeline import random @outputs.series.generic('number_list') class GenerateNumbers(Block): def run (self, number_list): for i in range(1, 100): n = random.randint(1, 1000) number_list.put(n) @inputs.series.generic('number_list') @inputs.atomic.generic('factor') @outputs.series.generic('factor_list') class MultiplyByFactor(Block): def run (self, number_list, factor, factor_list): for number in number_list: res = number * factor factor_list.put(res) @inputs.series.generic('factor_list') class SumListElements(Block): def run(self, factor_list): factor_sum = 0 for factor in factor_list: factor_sum += factor print(factor_sum)

To create a pipeline, the output of one block is chained as an input to the another block. In the following example of the pipeline, the output of GenerateNumbers is passed as an input to the MultiplyByFactor and the output of MultiplyByFactor is passed as in input to the SumListElements

A specific variable that needs to be passed to the next block can be accessed from the previous blocks object. As shown in the following pipeline, the number list which is passed to the MultiplyByFactor block is accessed as generate_nums.number_list.

  • To create a pipeline, the output of one block is chained as an input to the another block. In the following example of the pipeline, the output of GenerateNumbers is passed as an input to the MultiplyByFactor and the output of MultiplyByFactor is passed as in input to the SumListElements A specific variable that needs to be passed to the next block can be accessed from the previous blocks object. As shown in the following pipeline, the number list which is passed to the MultiplyByFactor block is accessed as generate_nums.number_list.
  • pipeline = Pipeline(targets=[sum_list_elements])
  • pipeline.show()
  • pipeline.execute()

Leave a Reply