Beispiel #1
0
def sched(ch, graph):
    """Sits in an infinite loop waiting on the channel to receive data.

    The procedure prolog takes care of sorting the
    input graph into a dependency list and initializing
    the filter tasklets used to construct the graph.

    @param graph: The graph representing the work flow
    @type graph: Python dict organized as a graph struct
    @param ch: The stackless channel to listen on
    @type ch: stackless.channel
    @return: nothing
    """
    # Added so that incoming data is fed to every input adapter
    # should check if in exists and create it if it doesn't
    # because a user could remove the input port by accident
    nodes = connect_graph_components(graph)
    tasks = schedule_recursively(nodes)
    inputEdges = []
    # Connect all the adapters to the input
    for node in nodes:
        if node.get_type() == 'ADAPTER':
            ie = Pype()
            node.connect_input('in', ie)
            inputEdges.append(ie)

    while True:
        data = ch.receive()
        for ie in inputEdges:
            ie.send(data)
        try:
            tasks[0].run()
        except:
            traceback.print_exc()
Beispiel #2
0
def sched(ch, graph):
    """Sits in an infinite loop waiting on the channel to receive data.

    The procedure prolog takes care of sorting the
    input graph into a dependency list and initializing
    the filter tasklets used to construct the graph.

    @param graph: The graph representing the work flow
    @type graph: Python dict organized as a graph struct
    @param ch: The stackless channel to listen on
    @type ch: stackless.channel
    @return: nothing
    """
    # Added so that incoming data is fed to every input adapter
    # should check if in exists and create it if it doesn't
    # because a user could remove the input port by accident
    nodes = connect_graph_components(graph)
    tasks = schedule_recursively(nodes)
    inputEdges = []
    # Connect all the adapters to the input
    for node in nodes:
        if node.get_type() == 'ADAPTER':
            ie = Pype()
            node.connect_input('in', ie)
            inputEdges.append(ie)

    while True:
        data = ch.receive()
        for ie in inputEdges:
            ie.send(data)
        try:
            tasks[0].run()
        except:
            traceback.print_exc()
    print 'Connection status for HelloWorld port "out":', \
                                                    hello.is_connected('out')

    # we need two pypes (2 edges)
    p1 = Pype()
    p2 = Pype()

    # A component is written as a stackless tasklet
    # We need to let stackless know. We only need a reference
    # to the first tasklet which is where we will send data
    t = stackless.tasklet(hello.run)()
    stackless.tasklet(printer.run)()

    print 'Connecting ports now...'
    # now we connect the nodes using the pypes we created
    hello.connect_input('in', p1)
    hello.connect_output('out', p2)
    printer.connect_input('in', p2)

    # Now the connection status on "out" should be True since we've just connected it
    print 'Connection status now for HelloWorld port "out":', \
                                                    hello.is_connected('out')

    # send some data through this pipeline
    print 'Sending some test data...\n'
    for name in ['Tom', 'Dick', 'Harry']:
        p1.send(name)
        # we need to "trigger" the first stackless tasklet
        t.run()
    else:
        print 'HelloWorld does not contain a port called "test2"'

    print 'Connection status for HelloWorld port "out":', hello.is_connected("out")

    # we need two pypes (2 edges)
    p1 = Pype()
    p2 = Pype()

    # A component is written as a stackless tasklet
    # We need to let stackless know. We only need a reference
    # to the first tasklet which is where we will send data
    t = stackless.tasklet(hello.run)()
    stackless.tasklet(printer.run)()

    print "Connecting ports now..."
    # now we connect the nodes using the pypes we created
    hello.connect_input("in", p1)
    hello.connect_output("out", p2)
    printer.connect_input("in", p2)

    # Now the connection status on "out" should be True since we've just connected it
    print 'Connection status now for HelloWorld port "out":', hello.is_connected("out")

    # send some data through this pipeline
    print "Sending some test data...\n"
    for name in ["Tom", "Dick", "Harry"]:
        p1.send(name)
        # we need to "trigger" the first stackless tasklet
        t.run()