def ProcessPipeline(*components): exchange = pprocess.Exchange() debug = False chans = [] print "TESTING ME" for comp in components: A = ProcessWrapComponent(comp) chan = A.activate() chans.append(chan) exchange.add(chan) mappings = {} for i in xrange(len(components) - 1): ci, cin = chans[i], chans[i + 1] mappings[(ci, "outbox")] = (cin, "inbox") mappings[(ci, "signal")] = (cin, "control") while 1: for chan in exchange.ready(0): D = chan._receive() try: dest = mappings[(chan, D[1])] dest[0]._send((D[0], dest[1])) print "FORWARDED", D except KeyError: if debug: print "WARNING: unlinked box sent data" print "This may be an error for your logic" print "chan, D[1] D[0]", print chan, D[1], repr(D[0]) pprint.pprint(mappings) time.sleep(0.1)
def main(self): exchange = pprocess.Exchange() chans = [] for comp in self.components: A = ProcessWrapComponent(comp) chan = A.activate() chans.append(chan) exchange.add(chan) mappings = {} for i in range(len(self.components) - 1): mappings[(chans[i], "outbox")] = (chans[i + 1], "inbox") mappings[(chans[i], "signal")] = (chans[i + 1], "control") while 1: for chan in exchange.ready(0): D = chan._receive() dest = mappings[(chan, D[1])] if chan != chans[-1]: dest[0]._send((D[0], dest[1])) else: self.send(D[0], D[1]) # Pass through outbound while self.dataReady("inbox"): D = self.recv("inbox") chans[0]._send((D, "inbox")) # Pass through inbound while self.dataReady("control"): D = self.recv("inbox") chans[0]._send((D, "control")) # Pass through inbound yield 1
def __init__(self, somecomponent): # print ("somecomponent.name",somecomponent.name) self.exchange = pprocess.Exchange() self.channel = None self.inbound = [] self.thecomponent = somecomponent self.ce = None self.tick = time.time()
def __init__(self, somecomponent): self.wrapped = somecomponent.__class__.__name__ print "wrapped a", self.wrapped self.exchange = pprocess.Exchange() self.channel = None self.inbound = [] self.C = somecomponent self.ce = None self.tick = time.time()
def activate(self): channel = pprocess.start(self.run, None, None, named1=None, named2=None) exchange = pprocess.Exchange() exchange.add(channel) return exchange
def ProcessGraphline(**graphline_spec): chans = [] count = 0 component_to_chan = {} mappings = {} debug = graphline_spec.get("__debug", False) chan_to_compname = {} exchange = pprocess.Exchange() for comp in graphline_spec: if comp != "linkages" and comp[:2] != "__": A = ProcessWrapComponent(graphline_spec[comp]) chan = A.activate() chans.append(chan) chan_to_compname[chan] = comp exchange.add(chan) component_to_chan[comp] = chan # print (comp, chan) count += 1 linkages = graphline_spec.get("linkages", {}) for source in linkages: sink = linkages[source] mappings[component_to_chan[source[0]], source[1]] = component_to_chan[sink[0]], sink[1] while 1: for chan in exchange.ready(0): # print ("CHAN", chan, chan_to_compname[ chan ]) D = chan._receive() # print ("DO WE EVEN GET HERE", D) try: dest = mappings[(chan, D[1])] dest[0]._send((D[0], dest[1])) except KeyError: # This error means that some component in the graphline spat out some data, # but the outbox it was sent to isn't linked anyway. This may be an error, # but generally speaking is not likely to be. # # As a result, we suppress this error. # This would be nicer to make conditional, but at present we don't have a # naming mechanism in general to do this. Though __debug=1 as a parameter # seems reasonable. # # If someone needs to debug this, they can enable this: # if debug: print( "WARNING: Data sent to outbox not linked to anywhere. Error?" ) print("chan, D[1] D[0]", chan, D[1], repr(D[0])) pprint.pprint(mappings) time.sleep(0.001)
def ProcessPipeline(*components): exchange = pprocess.Exchange() debug = False chans = [] # print ("TESTING ME") for comp in components: A = ProcessWrapComponent(comp) chan = A.activate() chans.append(chan) exchange.add(chan) mappings = {} for i in range(len(components) - 1): mappings[(chans[i], "outbox")] = (chans[i + 1], "inbox") mappings[(chans[i], "signal")] = (chans[i + 1], "control") while 1: for chan in exchange.ready(0): D = chan._receive() try: dest = mappings[(chan, D[1])] dest[0]._send((D[0], dest[1])) # print ("FORWARDED", D) except KeyError: # This error means that some component in the graphline spat out some data, # but the outbox it was sent to isn't linked anyway. This may be an error, # but generally speaking is not likely to be. # # As a result, we suppress this error. # This would be nicer to make conditional, but at present we don't have a # naming mechanism in general to do this. Though __debug=1 as a parameter # seems reasonable. # # If someone needs to debug this, they can enable this: # if debug: print( "WARNING: Data sent to outbox not linked to anywhere. Error?" ) print("chan, D[1] D[0]", chan, D[1], repr(D[0])) pprint.pprint(mappings) time.sleep(0.1)
def __init__(self): self.exchange = pprocess.Exchange() self.channel = None self.inbound = []