Пример #1
0
 def __init__(self, srv_address, context=None, retry_timeout=-1, **kwargs):
     # Get parameters
     srv_param = parse_address(srv_address)
     cli_param = dict()
     for k in ['protocol', 'host', 'port']:
         cli_param[k] = kwargs.pop(k, srv_param[k])
     context = context or _global_context
     # Create new address for the frontend
     if cli_param['protocol'] in ['inproc', 'ipc']:
         cli_param['host'] = str(uuid.uuid4())
     cli_address = format_address(cli_param['protocol'], cli_param['host'])
     self.cli_socket = context.socket(zmq.ROUTER)
     self.cli_address = bind_socket(self.cli_socket,
                                    cli_address,
                                    retry_timeout=retry_timeout)
     self.cli_socket.setsockopt(zmq.LINGER, 0)
     CommBase.register_comm('ZMQComm', 'ROUTER_server_' + self.cli_address,
                            self.cli_socket)
     # Bind backend
     self.srv_socket = context.socket(zmq.DEALER)
     self.srv_socket.setsockopt(zmq.LINGER, 0)
     self.srv_address = bind_socket(self.srv_socket,
                                    srv_address,
                                    retry_timeout=retry_timeout)
     CommBase.register_comm('ZMQComm', 'DEALER_server_' + self.srv_address,
                            self.srv_socket)
     # Set up poller
     # self.poller = zmq.Poller()
     # self.poller.register(frontend, zmq.POLLIN)
     self.reply_socket = None
     # Set name
     super(ZMQProxy, self).__init__(self.srv_address, self.cli_address,
                                    **kwargs)
     self.name = 'ZMQProxy.%s' % srv_address
Пример #2
0
def test_queue():
    r"""Test creation/removal of queue."""
    mq = IPCComm.get_queue()
    key = str(mq.key)
    assert (CommBase.is_registered('IPCComm', key))
    CommBase.unregister_comm('IPCComm', key, dont_close=True)
    nt.assert_raises(KeyError, IPCComm.remove_queue, mq)
    CommBase.register_comm('IPCComm', key, mq)
    IPCComm.remove_queue(mq)
    assert (not CommBase.is_registered('IPCComm', key))
Пример #3
0
def test_registry():
    r"""Test registry of comm."""
    comm_class = 'CommBase'
    key = 'key1'
    value = None
    assert(not CommBase.is_registered(comm_class, key))
    assert(not CommBase.unregister_comm(comm_class, key))
    nt.assert_equal(CommBase.get_comm_registry(None), {})
    nt.assert_equal(CommBase.get_comm_registry(comm_class), {})
    CommBase.register_comm(comm_class, key, value)
    assert(key in CommBase.get_comm_registry(comm_class))
    assert(CommBase.is_registered(comm_class, key))
    assert(not CommBase.unregister_comm(comm_class, key, dont_close=True))
    CommBase.register_comm(comm_class, key, value)
    assert(not CommBase.unregister_comm(comm_class, key))
Пример #4
0
def get_queue(qid=None):
    r"""Create or return a sysv_ipc.MessageQueue and register it.

    Args:
        qid (int, optional): If provided, ID for existing queue that should be
           returned. Defaults to None and a new queue is returned.

    Returns:
        :class:`sysv_ipc.MessageQueue`: Message queue.

    """
    if _ipc_installed:
        kwargs = dict(max_message_size=tools.get_CIS_MSG_MAX())
        if qid is None:
            kwargs['flags'] = sysv_ipc.IPC_CREX
        mq = sysv_ipc.MessageQueue(qid, **kwargs)
        key = str(mq.key)
        CommBase.register_comm('IPCComm', key, mq)
        return mq
    else:  # pragma: windows
        logging.warning("IPC not installed. Queue cannot be returned.")
        return None