Created
February 1, 2016 11:05
-
-
Save night-crawler/e05e455d6915c93ffcba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import asyncio | |
| import aiozmq.rpc | |
| @asyncio.coroutine | |
| def get_rpc_connection(connect='', loop=None): | |
| timeout = 1 | |
| connection = yield from aiozmq.rpc.connect_rpc(connect=connect, timeout=timeout, loop=loop) | |
| return connection | |
| def main(): | |
| loop = asyncio.get_event_loop() | |
| connection_tasks = [ | |
| asyncio.ensure_future(get_rpc_connection(connect='tcp://127.0.0.1:45000', loop=loop)), | |
| asyncio.ensure_future(get_rpc_connection(connect='tcp://127.0.0.1:45001', loop=loop)), | |
| asyncio.ensure_future(get_rpc_connection(connect='tcp://127.0.0.1:45001', loop=loop)), | |
| ] | |
| loop.run_until_complete(asyncio.wait(connection_tasks)) | |
| conn1, conn2, conn3 = [conn.result() for conn in connection_tasks] | |
| tasks = [ | |
| asyncio.ensure_future(conn1.call.detail_user('admin')), | |
| asyncio.ensure_future(conn2.call.detail_user('admin')), | |
| asyncio.ensure_future(conn3.call.detail_user('fail')), | |
| ] | |
| loop.run_until_complete(asyncio.wait(tasks)) | |
| for t in tasks: | |
| print(t.result()) | |
| conn1.close() | |
| conn2.close() | |
| conn2.close() | |
| loop.close() | |
| if __name__ == '__main__': | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment