예제 #1
0
파일: rpc.py 프로젝트: victorpoluceno/xwing
from xwing.mailbox import initialize, spawn, run, stop
initialize()


class Server(object):

    def hello_world(self):
        return 'Hello World!'

    def run(self):
        async def rpc_server(mailbox, server):
            while True:
                function, pid = await mailbox.recv()
                print('Got call from: ', pid)

                result = getattr(server, function)()
                await mailbox.send(pid, result)

        spawn(rpc_server, self, name='rpc_server')


class Client(object):

    def __init__(self, server_pid):
        self.server_pid = server_pid

    def call(self, function):
        async def dispatch(mailbox, function):
            await mailbox.send(self.server_pid, function, mailbox.pid)
            result = await mailbox.recv()
            print('Got result: ', result)
예제 #2
0
 def setup_class(self):
     initialize()
예제 #3
0
파일: run.py 프로젝트: victorpoluceno/xwing
def run_bench(start, duration, data=b'x'):
    initialize()  # initialize a new node with a new event loop
    spawn(send, start, duration, b'x', 'server')
    run()