コード例 #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
ファイル: test_rapid_reconnect.py プロジェクト: yltang52/pyzo
def connect_test():
    c1 = yoton.Context(verbosity)
    c2 = yoton.Context(verbosity)
    c3 = yoton.Context(verbosity)
    
    c1.bind('localhost:test1')
    c2.connect('localhost:test1')
    
    c2.bind('localhost:test2')
    c3.connect('localhost:test2')
    
    c1.close()
    c2.close()
    c3.close()
コード例 #3
0
    def __init__(self, manager, info, name=""):
        self._manager = manager

        # Store info that defines the kernel
        self._originalInfo = KernelInfo(info)

        # Make a copy for the current version. This copy is re-created on
        # each restart
        self._info = ssdf.copy(self._originalInfo)

        # Store name (or should the name be defined in the info struct)
        self._name = name

        # Create context for the connection to the kernel and IDE's
        # This context is persistent (it stays as long as this KernelBroker
        # instance is alive).
        self._context = yoton.Context()
        self._kernelCon = None
        self._ctrl_broker = None

        # Create yoton-based timer
        self._timer = yoton.Timer(0.2, oneshot=False)
        self._timer.bind(self.mainLoopIter)

        # Kernel process and connection (these are replaced on restarting)
        self._reset()

        # For restarting after terminating
        self._pending_restart = None
コード例 #4
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)
コード例 #5
0
    def test_req_rep2(self):

        # Test multiple requesters and multiple repliers

        # Connect
        if True:
            self._context1.bind("localhost:test1")
            self._context3.connect("localhost:test1")
            #
            self._context1.bind("localhost:test2")
            self._context2.connect("localhost:test2")
        else:
            freeNode = yoton.Context()
            #
            self._context1.bind("localhost:test1")
            freeNode.connect("localhost:test1")
            freeNode.bind("localhost:test1f")
            self._context3.connect("localhost:test1f")
            #
            self._context1.bind("localhost:test2")
            self._context2.connect("localhost:test2")
        time.sleep(0.1)

        # Turn on 2 requesters and 3 repliers
        self._channel_rep1.set_mode("thread")  # threaded because simulating
        self._channel_rep2.set_mode("thread")  # different processes
        self._channel_rep3.set_mode("thread")

        # Define and register reply handler
        def reply_handler(future):
            reply = future.result()
            reqnr = future.reqnr

            echo, id = reply
            if echo.lower() == "stop":
                yoton.stop_event_loop()
            else:
                self.assertEqual(echo[:3], "msg")
                contextnr = {
                    self._context1.id: 1,
                    self._context2.id: 2,
                    self._context3.id: 3,
                }[long(id, 16)]
                print("request %s from %i handled by context %i." %
                      (echo, reqnr, contextnr))

        # Get echo functions
        echoFun1 = self._channel_req1.echo
        echoFun2 = self._channel_req2.echo

        # Send requests on req 1
        sleepTimes = [1, 0.1, 1, 0.6, 0.6, 0.6, 0.6, 0.6]
        for i in range(len(sleepTimes)):
            f = echoFun1("msg%i" % i, sleepTimes[i])
            f.add_done_callback(reply_handler)
            f.reqnr = 1

        # Send requests on req 2
        sleepTimes = [0.4, 0.4, 0.4, 0.4, 0.4]
        for i in range(len(sleepTimes)):
            f = echoFun2("msg%i" % i, sleepTimes[i])
            f.add_done_callback(reply_handler)
            f.reqnr = 2

        # Stop
        f = echoFun1("stop")
        f.add_done_callback(reply_handler)
        f.reqnr = 1

        # Enter event loop
        yoton.start_event_loop()
コード例 #6
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
コード例 #7
0
ファイル: start.py プロジェクト: tjguk/pyzo
"""

# This file is executed with the active directory one up from this file.

import os
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_debug = yoton.StateChannel(ct, 'stat-debug', yoton.OBJECT)
コード例 #8
0
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):
コード例 #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())
コード例 #10
0
ファイル: test_speed.py プロジェクト: vishalbelsare/pyzo
os.chdir("../..")
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 = []