Пример #1
0
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
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()