def main(number_of_workers=4, duration=30): start = time.monotonic() spawn(collector, number_of_workers, name='collector') executor = futures.ProcessPoolExecutor(max_workers=number_of_workers) for i in range(number_of_workers): node = get_node_instance() node.loop.create_task(dispatch(node.loop, executor, start, duration)) run()
def test_send_and_recv(self): async def echo_server(mailbox): message, pid = await mailbox.recv() await mailbox.send(pid, message) async def echo_client(mailbox, pid_server): await mailbox.send(pid_server, 'hello', mailbox.pid) await mailbox.recv() pid = spawn(echo_server) spawn(echo_client, pid) run()
def test_send_and_recv(self): async def run(self): data = b'ping' await self.connection.send(data) await self.connection.recv() return True event_loop = asyncio.get_event_loop() assert event_loop.run_until_complete(run(self))
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) spawn(dispatch, function) if __name__ == '__main__': # python examples/mailbox/rpc.py server = Server() server.run() client = Client('[email protected]') client.call('hello_world') try: run() except KeyboardInterrupt: print('Stopping...') stop()
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()