def setUp(self): # Create contexts self._context1 = c1 = yoton.Context() self._context2 = c2 = yoton.Context() self._context3 = c3 = yoton.Context() # Create pub sub channels self._channel_pub1 = yoton.PubChannel(c1, "foo") self._channel_pub2 = yoton.PubChannel(c2, "foo") self._channel_pub3 = yoton.PubChannel(c3, "foo") # self._channel_sub1 = yoton.SubChannel(c1, "foo") self._channel_sub2 = yoton.SubChannel(c2, "foo") self._channel_sub3 = yoton.SubChannel(c3, "foo") # Create req rep channels self._channel_req1 = yoton.ReqChannel(c1, "bar") self._channel_req2 = yoton.ReqChannel(c2, "bar") self._channel_req3 = yoton.ReqChannel(c3, "bar") # self._channel_rep1 = yoton.RepChannel(c1, "bar") self._channel_rep2 = yoton.RepChannel(c2, "bar") self._channel_rep3 = yoton.RepChannel(c3, "bar") # Create state channels self._channel_state1 = yoton.StateChannel(c1, "spam") self._channel_state2 = yoton.StateChannel(c2, "spam") self._channel_state3 = yoton.StateChannel(c3, "spam")
def connectToKernel(self, info): """ connectToKernel() Create kernel and connect to it. """ # Create yoton context self._context = ct = yoton.Context() # Create stream channels self._strm_out = yoton.SubChannel(ct, 'strm-out') self._strm_err = yoton.SubChannel(ct, 'strm-err') self._strm_raw = yoton.SubChannel(ct, 'strm-raw') self._strm_echo = yoton.SubChannel(ct, 'strm-echo') self._strm_prompt = yoton.SubChannel(ct, 'strm-prompt') self._strm_broker = yoton.SubChannel(ct, 'strm-broker') self._strm_action = yoton.SubChannel(ct, 'strm-action', yoton.OBJECT) # Set channels to sync mode. This means that if the IEP cannot process # the messages fast enough, the sending side is blocked for a short # while. We don't want our users to miss any messages. for c in [self._strm_out, self._strm_err]: c.set_sync_mode(True) # Create control channels self._ctrl_command = yoton.PubChannel(ct, 'ctrl-command') self._ctrl_code = yoton.PubChannel(ct, 'ctrl-code', yoton.OBJECT) self._ctrl_broker = yoton.PubChannel(ct, 'ctrl-broker') # Create status channels self._stat_interpreter = yoton.StateChannel(ct, 'stat-interpreter') self._stat_debug = yoton.StateChannel(ct, 'stat-debug', yoton.OBJECT) self._stat_startup = yoton.StateChannel(ct, 'stat-startup', yoton.OBJECT) self._stat_startup.received.bind(self._onReceivedStartupInfo) # Create introspection request channel self._request = yoton.ReqChannel(ct, 'reqp-introspect') # Connect! The broker will only start the kernel AFTER # we connect, so we do not miss out on anything. slot = iep.localKernelManager.createKernel(finishKernelInfo(info)) self._brokerConnection = ct.connect('localhost:%i' % slot) self._brokerConnection.closed.bind(self._onConnectionClose)
def _create_channels(self): ct = self._context # Close any existing channels first self._context.close_channels() # Create stream channels. # Stdout is for the C-level stdout/stderr streams. self._strm_broker = yoton.PubChannel(ct, 'strm-broker') self._strm_raw = yoton.PubChannel(ct, 'strm-raw') self._strm_prompt = yoton.PubChannel(ct, 'strm-prompt') # Create control channel so that the IDE can control restarting etc. self._ctrl_broker = yoton.SubChannel(ct, 'ctrl-broker') # Status channel to pass startup parameters to the kernel self._stat_startup = yoton.StateChannel(ct, 'stat-startup', yoton.OBJECT) # We use the stat-interpreter to set the status to dead when kernel dies self._stat_interpreter = yoton.StateChannel(ct, 'stat-interpreter') # Create introspect channel so we can interrupt and terminate self._reqp_introspect = yoton.ReqChannel(ct, 'reqp-introspect')
class Adder(yoton.RepChannel): def add(self, item1, item2): return item1 + item2 # Create a context and a rep channel ct1 = yoton.Context(verbose=verbosity) rep = Adder(ct1, 'duplicate') # Connect and turn duplicator on ct1.bind('publichost:test') rep.set_mode('thread') ## ========== Other end import yoton verbosity = 0 # Create a context and a req channel ct2 = yoton.Context(verbose=verbosity) req = yoton.ReqChannel(ct2, 'duplicate') # Connect ct2.connect('publichost:test') # Duplicate a string print(req.add('foo', 'bar').result(1)) print(req.add(3,4).result(1))
# Create a replier class by subclassing RepChannel class Adder(yoton.RepChannel): def add(self, item1, item2): return item1 + item2 # Create a context and a rep channel ct1 = yoton.Context(verbose=verbosity) rep = Adder(ct1, "duplicate") # Connect and turn duplicator on ct1.bind("publichost:test") rep.set_mode("thread") ## ========== Other end import yoton verbosity = 0 # Create a context and a req channel ct2 = yoton.Context(verbose=verbosity) req = yoton.ReqChannel(ct2, "duplicate") # Connect ct2.connect("publichost:test") # Duplicate a string print(req.add("foo", "bar").result(1)) print(req.add(3, 4).result(1))
rep = Reducer(ct1, 'reduce') # Connect and turn duplicator on ct1.bind('publichost:test') rep.set_mode('event') ## ========== Other end import yoton import time verbosity = 0 # Create a context and a req channel ct2 = yoton.Context(verbose=verbosity) req = yoton.ReqChannel(ct2, 'reduce') # Connect ct2.connect('publichost:test') # Create reply handler and bind it def reply_handler(future): # Check error, cancelled, or get number if future.exception(): # Calling result() would raise the exception, so lets just # print it and make up our own number print('oops: ' + str(future.exception())) number = 1 elif future.cancelled():
rep = Reducer(ct1, "reduce") # Connect and turn duplicator on ct1.bind("publichost:test") rep.set_mode("event") ## ========== Other end import yoton import time verbosity = 0 # Create a context and a req channel ct2 = yoton.Context(verbose=verbosity) req = yoton.ReqChannel(ct2, "reduce") # Connect ct2.connect("publichost:test") # Create reply handler and bind it def reply_handler(future): # Check error, cancelled, or get number if future.exception(): # Calling result() would raise the exception, so lets just # print it and make up our own number print("oops: " + str(future.exception())) number = 1 elif future.cancelled():