コード例 #1
0
    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")
コード例 #2
0
    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)
コード例 #3
0
ファイル: kernelbroker.py プロジェクト: sunlinjin/pyzo
 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')
コード例 #4
0
ファイル: status.py プロジェクト: vishalbelsare/pyzo
# -*- coding: utf-8 -*-

## Connect two context

import yoton
import time

# Context 1
ct1 = yoton.Context()
pub1 = yoton.StateChannel(ct1, "state A")
pub1.send("READY")

# Context 2
ct2 = yoton.Context()
pub2 = yoton.StateChannel(ct2, "state A")

# Context 3
ct3 = yoton.Context()
sub1 = yoton.StateChannel(ct3, "state A")

# Connect
ct1.bind("localhost:test1")
ct2.connect("localhost:test1")
ct2.bind("localhost:test2")
ct3.connect("localhost:test2")

# Get status (but wait first)
time.sleep(0.3)
print(sub1.recv())

# New status
コード例 #5
0
ファイル: start.py プロジェクト: tjguk/pyzo
# Create a yoton context. All channels are stored at the context.
ct = yoton.Context()

# Create control channels
ct._ctrl_command = yoton.SubChannel(ct, 'ctrl-command')
ct._ctrl_code = yoton.SubChannel(ct, 'ctrl-code', yoton.OBJECT)

# Create stream channels
ct._strm_out = yoton.PubChannel(ct, 'strm-out')
ct._strm_err = yoton.PubChannel(ct, 'strm-err')
ct._strm_echo = yoton.PubChannel(ct, 'strm-echo')
ct._strm_prompt = yoton.PubChannel(ct, 'strm-prompt')
ct._strm_action = yoton.PubChannel(ct, 'strm-action', yoton.OBJECT)

# Create status channels
ct._stat_interpreter = yoton.StateChannel(ct, 'stat-interpreter')
ct._stat_debug = yoton.StateChannel(ct, 'stat-debug', yoton.OBJECT)
ct._stat_startup = yoton.StateChannel(ct, 'stat-startup', yoton.OBJECT)
ct._stat_breakpoints = yoton.StateChannel(ct, 'stat-breakpoints', yoton.OBJECT)

# Connect (port number given as command line argument)
# Important to do this *before* replacing the stdout etc, because if an
# error occurs here, it will be printed in the shell.
port = int(sys.argv[1])
ct.connect('localhost:'+str(port), timeout=1.0)

# Create file objects for stdin, stdout, stderr
sys.stdin = yoton.FileWrapper( ct._ctrl_command, echo=ct._strm_echo, isatty=True)
sys.stdout = yoton.FileWrapper( ct._strm_out, 256, isatty=True)
sys.stderr = yoton.FileWrapper( ct._strm_err, 256, isatty=True)
コード例 #6
0
#            / ct3
# ct1 - ct2
#            \ ct4 - ct5
ct1.bind('localhost:split1')
ct2.connect('localhost:split1')
#
ct2.bind('localhost:split2')
ct3.connect('localhost:split2')
#
ct2.bind('localhost:split3')
ct4.connect('localhost:split3')
#
ct4.bind('localhost:split4')
ct5.connect('localhost:split4')

# Create channels
if True:
    pub1 = yoton.PubChannel(ct1, 'splittest')
    sub1 = yoton.SubChannel(ct3, 'splittest')
    sub2 = yoton.SubChannel(ct5, 'splittest')
else:
    pub1 = yoton.StateChannel(ct1, 'splittest')
    sub1 = yoton.StateChannel(ct3, 'splittest')
    sub2 = yoton.StateChannel(ct5, 'splittest')

# Go!
pub1.send('Hello you two!')
time.sleep(0.5)
print(sub1.recv())
print(sub2.recv())
コード例 #7
0
ファイル: status.py プロジェクト: yltang52/pyzo
# -*- coding: utf-8 -*-

## Connect two context

import yoton
import time

# Context 1
ct1 = yoton.Context()
pub1 = yoton.StateChannel(ct1, 'state A')
pub1.send('READY')

# Context 2
ct2 = yoton.Context()
pub2 = yoton.StateChannel(ct2, 'state A')

# Context 3
ct3 = yoton.Context()
sub1 = yoton.StateChannel(ct3, 'state A')

# Connect
ct1.bind('localhost:test1')
ct2.connect('localhost:test1')
ct2.bind('localhost:test2')
ct3.connect('localhost:test2')

# Get status (but wait first)
time.sleep(0.3)
print(sub1.recv())

# New status
コード例 #8
0
#            / ct3
# ct1 - ct2
#            \ ct4 - ct5
ct1.bind("localhost:split1")
ct2.connect("localhost:split1")
#
ct2.bind("localhost:split2")
ct3.connect("localhost:split2")
#
ct2.bind("localhost:split3")
ct4.connect("localhost:split3")
#
ct4.bind("localhost:split4")
ct5.connect("localhost:split4")

# Create channels
if True:
    pub1 = yoton.PubChannel(ct1, "splittest")
    sub1 = yoton.SubChannel(ct3, "splittest")
    sub2 = yoton.SubChannel(ct5, "splittest")
else:
    pub1 = yoton.StateChannel(ct1, "splittest")
    sub1 = yoton.StateChannel(ct3, "splittest")
    sub2 = yoton.StateChannel(ct5, "splittest")

# Go!
pub1.send("Hello you two!")
time.sleep(0.5)
print(sub1.recv())
print(sub2.recv())
コード例 #9
0
ファイル: start.py プロジェクト: vishalbelsare/pyzo
# Create a yoton context. All channels are stored at the context.
ct = yoton.Context()

# Create control channels
ct._ctrl_command = yoton.SubChannel(ct, "ctrl-command")
ct._ctrl_code = yoton.SubChannel(ct, "ctrl-code", yoton.OBJECT)

# Create stream channels
ct._strm_out = yoton.PubChannel(ct, "strm-out")
ct._strm_err = yoton.PubChannel(ct, "strm-err")
ct._strm_echo = yoton.PubChannel(ct, "strm-echo")
ct._strm_prompt = yoton.PubChannel(ct, "strm-prompt")
ct._strm_action = yoton.PubChannel(ct, "strm-action", yoton.OBJECT)

# Create status channels
ct._stat_interpreter = yoton.StateChannel(ct, "stat-interpreter")
ct._stat_cd = yoton.StateChannel(ct, "stat-cd")
ct._stat_debug = yoton.StateChannel(ct, "stat-debug", yoton.OBJECT)
ct._stat_startup = yoton.StateChannel(ct, "stat-startup", yoton.OBJECT)
ct._stat_breakpoints = yoton.StateChannel(ct, "stat-breakpoints", yoton.OBJECT)

# Connect (port number given as command line argument)
# Important to do this *before* replacing the stdout etc, because if an
# error occurs here, it will be printed in the shell.
port = int(sys.argv[1])
ct.connect("localhost:" + str(port), timeout=1.0)

# Create file objects for stdin, stdout, stderr
sys.stdin = yoton.FileWrapper(ct._ctrl_command,
                              echo=ct._strm_echo,
                              isatty=True)