Beispiel #1
0
def restart_hub():
    from evy import hubs

    hub = hubs.get_hub()
    hub_shortname = hub.__module__.split('.')[-1]
    # don't restart the pyevent hub; it's not necessary
    if hub_shortname != 'pyevent':
        hub.abort()
        hubs.use_hub(hub_shortname)
Beispiel #2
0
def restart_hub ():
    from evy import hubs

    hub = hubs.get_hub()
    hub_shortname = hub.__module__.split('.')[-1]
    # don't restart the pyevent hub; it's not necessary
    if hub_shortname != 'pyevent':
        hub.abort()
        hubs.use_hub(hub_shortname)
$ python examples/distributed_websocket_chat.py -p tcp://127.0.0.1:12345 -s tcp://127.0.0.1:12346 7000

So all messages are published to port 12345 and the device forwards all the
messages to 12346 where they are subscribed to
"""
import os, sys
import evy
from collections import defaultdict
from evy import spawn_n, sleep
from evy import wsgi
from evy import websocket
from evy.patched import zmq
from evy.hubs import get_hub, use_hub
from uuid import uuid1

use_hub('zeromq')
ctx = zmq.Context()


class IDName(object):
    def __init__(self):
        self.id = uuid1()
        self.name = None

    def __str__(self):
        if self.name:
            return self.name
        else:
            return str(self.id)

    def pack_message(self, msg):
Beispiel #4
0
    def run (self):
        while self.counter <= CONTEXT_SWITCHES:
            self.wait_event.wait()
            self.wait_event.clear()
            self.counter += 1
            self.event.set()


def test_thread ():
    event1 = threading.Event()
    event2 = threading.Event()
    event1.set()
    thread1 = BenchThread(event1, event2)
    thread2 = BenchThread(event2, event1)
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()

print "Testing with %d context switches" % CONTEXT_SWITCHES
start = time.time()
test_thread()
print "threading: %.02f seconds" % (time.time() - start)

hubs.use_hub()
start = time.time()
test_evy()
print "evy hub:   %.02f seconds" % (time.time() - start)


Beispiel #5
0
import evy, sys

from evy.patched import socket, zmq
from evy.hubs import use_hub

use_hub('zeromq')

ADDR = 'ipc:///tmp/chat'

ctx = zmq.Context()

def publish (writer):
    print "connected"
    socket = ctx.socket(zmq.SUB)

    socket.setsockopt(zmq.SUBSCRIBE, "")
    socket.connect(ADDR)
    evy.sleep(0.1)

    while True:
        msg = socket.recv_pyobj()
        str_msg = "%s: %s" % msg
        writer.write(str_msg)
        writer.flush()


PORT = 3001

def read_chat_forever (reader, pub_socket):
    line = reader.readline()
Beispiel #6
0
    def run(self):
        while self.counter <= CONTEXT_SWITCHES:
            self.wait_event.wait()
            self.wait_event.clear()
            self.counter += 1
            self.event.set()


def test_thread():
    event1 = threading.Event()
    event2 = threading.Event()
    event1.set()
    thread1 = BenchThread(event1, event2)
    thread2 = BenchThread(event2, event1)
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()


print "Testing with %d context switches" % CONTEXT_SWITCHES
start = time.time()
test_thread()
print "threading: %.02f seconds" % (time.time() - start)

hubs.use_hub()
start = time.time()
test_evy()
print "evy hub:   %.02f seconds" % (time.time() - start)