Esempio n. 1
0
    def test_pub_sub_select_channel(self):

        # Connect
        self._context1.bind("localhost:test1")
        self._context2.connect("localhost:test1")

        # Create channels
        pub1 = yoton.PubChannel(self._context1, "foo1")
        pub2 = yoton.PubChannel(self._context1, "foo2")
        #
        sub1 = yoton.SubChannel(self._context2, "foo1")
        sub2 = yoton.SubChannel(self._context2, "foo2")

        # Send a bunch of messages
        ii = [0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1]
        for i in range(len(ii)):
            pub = [pub1, pub2][ii[i]]
            pub.send(str(i))

        time.sleep(0.1)

        # Receive in right order
        count = 0
        while True:
            sub = yoton.select_sub_channel(sub1, sub2)
            if sub:
                i = int(sub.recv())
                self.assertEqual(i, count)
                count += 1
            else:
                break

        # Test count
        self.assertEqual(count, len(ii))
Esempio n. 2
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")
Esempio n. 3
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)
Esempio n. 4
0
 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')
Esempio n. 5
0
File: start.py Progetto: tjguk/pyzo
import time
import yoton
import __main__ # we will run code in the __main__.__dict__ namespace


## Make connection object and get channels

# 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])
Esempio n. 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())
Esempio n. 7
0
# Create custom message type. (should be defined at both ends)
class NumberMessageType(yoton.MessageType):
    def message_from_bytes(self, bb):
        return float(bb.decode("utf-8"))

    def message_to_bytes(self, number):
        return str(number).encode("utf-8")

    def message_type_name(self):
        return "num"


# Create context, a channel, and connect
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, "numbers", NumberMessageType)
ct1.bind("publichost:test")

# Send a message
pub.send(42.9)


## ========== Other end

import yoton

verbosity = 0

# Create custom message type. (should be defined at both ends)
class NumberMessageType(yoton.MessageType):
    def message_from_bytes(self, bb):
Esempio n. 8
0
# -*- coding: utf-8 -*-
# This example illustrates a simple pub/sub pattern.
# This example can be run in one go or in two parts running in
# different processes.

## ========== One end

import yoton
verbosity = 0  # Python 2.4 can crash with verbosity on

# Create one context and a pub channel
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, 'chat')

# Connect
ct1.bind('publichost:test')

# Send
pub.send('hello world')

## ========== Other end

import yoton
verbosity = 0

# Create another context and a sub channel
ct2 = yoton.Context(verbose=verbosity)
sub = yoton.SubChannel(ct2, 'chat')

# Connect
ct2.connect('publichost:test')
Esempio n. 9
0
# -*- coding: utf-8 -*-
# This example creates three contexts that are connected in a row.
# A message is send at the first and received at the last.

import yoton

# Three contexts
verbosity = 2
c1 = yoton.Context(verbosity)
c2 = yoton.Context(verbosity)
c3 = yoton.Context(verbosity)
c4 = yoton.Context(verbosity)

# Connect in a row
addr = "localhost:whop"
c1.bind(addr + "+1")
c2.connect(addr + "+1")
c2.bind(addr + "+2")
c3.connect(addr + "+2")
c3.bind(addr + "+3")
c4.connect(addr + "+3")

# Create pub at first and sub at last
p = yoton.PubChannel(c1, "hop")
s = yoton.SubChannel(c4, "hop")

# Send a message.
p.send("hophophop")
print(s.recv())
Esempio n. 10
0
# -*- coding: utf-8 -*-
# This example demponstrates simple pub sub.
#
# This time in event driven mode. This example only works locally, as
# we cannot start two event loops :)

## ========== One end

import yoton

verbosity = 0

# Create a context and a pub channel
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, "foo")

# Connect and turn duplicator on
ct1.bind("publichost:test")


## ========== Other end

import yoton

verbosity = 0

# Create a context and a sub channel
ct2 = yoton.Context(verbose=verbosity)
sub = yoton.SubChannel(ct2, "foo")

# Connect, set channel to event driven mode
Esempio n. 11
0
# -*- coding: utf-8 -*-
# This example illustrates a simple pub/sub pattern.
# This example can be run in one go or in two parts running in
# different processes.

## ========== One end

import yoton

verbosity = 0  # Python 2.4 can crash with verbosity on

# Create one context and a pub channel
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, "chat")

# Connect
ct1.bind("publichost:test")

# Send
pub.send("hello world")

## ========== Other end

import yoton

verbosity = 0

# Create another context and a sub channel
ct2 = yoton.Context(verbose=verbosity)
sub = yoton.SubChannel(ct2, "chat")
Esempio n. 12
0
import yoton
verbosity = 0

# Create custom message type. (should be defined at both ends)
class NumberMessageType(yoton.MessageType):
    def message_from_bytes(self, bb):
        return float(bb.decode('utf-8'))
    def message_to_bytes(self, number):
        return str(number).encode('utf-8')
    def message_type_name(self):
        return 'num'

# Create context, a channel, and connect
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, 'numbers', NumberMessageType)
ct1.bind('publichost:test')

# Send a message
pub.send(42.9)


## ========== Other end

import yoton
verbosity = 0

# Create custom message type. (should be defined at both ends)
class NumberMessageType(yoton.MessageType):
    def message_from_bytes(self, bb):
        return float(bb)
Esempio n. 13
0
sys.path.insert(0, ".")

# Import yoton from there
import yoton

# Normal imports
import math
import time
import visvis as vv

## Run experiment with different message sizes

# Setup host
ct1 = yoton.Context()
ct1.bind("localhost:test")
c1 = yoton.PubChannel(ct1, "speedTest")

# Setup client
ct2 = yoton.SimpleSocket()
ct2.connect("localhost:test")
c2 = yoton.SubChannel(ct2, "speedTest")

# Init
minSize, maxSize = 2, 100 * 2**20
BPS = []
TPM = []
N = []
SIZE = []

# Loop
size = minSize
Esempio n. 14
0
# -*- coding: utf-8 -*-
# This example creates three contexts that are connected in a row.
# A message is send at the first and received at the last.

import yoton

# Three contexts
verbosity = 2
c1 = yoton.Context(verbosity)
c2 = yoton.Context(verbosity)
c3 = yoton.Context(verbosity)
c4 = yoton.Context(verbosity)

# Connect in a row
addr = 'localhost:whop'
c1.bind(addr + '+1')
c2.connect(addr + '+1')
c2.bind(addr + '+2')
c3.connect(addr + '+2')
c3.bind(addr + '+3')
c4.connect(addr + '+3')

# Create pub at first and sub at last
p = yoton.PubChannel(c1, 'hop')
s = yoton.SubChannel(c4, 'hop')

# Send a message.
p.send('hophophop')
print(s.recv())
Esempio n. 15
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())
Esempio n. 16
0
import sys
import time
import yoton
import __main__  # we will run code in the __main__.__dict__ namespace

## Make connection object and get channels

# 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.
Esempio n. 17
0
# -*- coding: utf-8 -*-
# This example demponstrates simple pub sub.
#
# This time in event driven mode. This example only works locally, as
# we cannot start two event loops :)

## ========== One end

import yoton
verbosity = 0

# Create a context and a pub channel
ct1 = yoton.Context(verbose=verbosity)
pub = yoton.PubChannel(ct1, 'foo')

# Connect and turn duplicator on
ct1.bind('publichost:test')


## ========== Other end

import yoton
verbosity = 0

# Create a context and a sub channel
ct2 = yoton.Context(verbose=verbosity)
sub = yoton.SubChannel(ct2, 'foo')

# Connect, set channel to event driven mode
ct2.connect('publichost:test')
Esempio n. 18
0
sys.path.insert(0,'.')

# Import yoton from there
import yoton

# Normal imports
import math
import time
import visvis as vv

## Run experiment with different message sizes

# Setup host
ct1 = yoton.Context()
ct1.bind('localhost:test')
c1 = yoton.PubChannel(ct1, 'speedTest')

# Setup client
ct2 = yoton.SimpleSocket()
ct2.connect('localhost:test')
c2 = yoton.SubChannel(ct2, 'speedTest')

# Init
minSize, maxSize = 2, 100*2**20
BPS = []
TPM = []
N = []
SIZE = []


# Loop