当前位置: 首页>>代码示例>>Python>>正文


Python zmq.LINGER属性代码示例

本文整理汇总了Python中zmq.LINGER属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.LINGER属性的具体用法?Python zmq.LINGER怎么用?Python zmq.LINGER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在zmq的用法示例。


在下文中一共展示了zmq.LINGER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forward_read_events

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def forward_read_events(fd, context=None):
    """Forward read events from an FD over a socket.

    This method wraps a file in a socket pair, so it can
    be polled for read events by select (specifically zmq.eventloop.ioloop)
    """
    if context is None:
        context = zmq.Context.instance()
    push = context.socket(zmq.PUSH)
    push.setsockopt(zmq.LINGER, -1)
    pull = context.socket(zmq.PULL)
    addr='inproc://%s'%uuid.uuid4()
    push.bind(addr)
    pull.connect(addr)
    forwarder = ForwarderThread(push, fd)
    forwarder.start()
    return pull 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:win32support.py

示例2: serve_data

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def serve_data(ds, addr):
    ctx = zmq.Context()
    socket = ctx.socket(zmq.PUSH)
    socket.set_hwm(10)
    socket.bind(addr)
    ds = RepeatedData(ds, -1)
    try:
        ds.reset_state()
        logger.info("Serving data at {}".format(addr))
        while True:
            for dp in ds.get_data():
                socket.send(dumps(dp), copy=False)
    finally:
        socket.setsockopt(zmq.LINGER, 0)
        socket.close()
        if not ctx.closed:
            ctx.destroy(0) 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:19,代码来源:remote.py

示例3: createZMQSocket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def createZMQSocket(self, sock_type):
        """Create a socket of the given sock_type and deactivate message dropping"""
        sock = self.ZMQcontext.socket(sock_type)
        sock.setsockopt(zmq.LINGER, LINGER_TIME)
        sock.setsockopt(zmq.IPV4ONLY, 0)

        # Remove message dropping
        sock.setsockopt(zmq.SNDHWM, 0)
        sock.setsockopt(zmq.RCVHWM, 0)
        try:
            sock.setsockopt(zmq.IMMEDIATE, 1)
        except:
            # This parameter was recently added by new libzmq versions
            pass

        # Don't accept unroutable messages
        if sock_type == zmq.ROUTER:
            sock.setsockopt(zmq.ROUTER_MANDATORY, 1)
        return sock 
开发者ID:soravux,项目名称:scoop,代码行数:21,代码来源:scoopzmq.py

示例4: _create_socket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def _create_socket(self, socket_type, linger_value):
        """
        Create a socket of the given type, bind it to a random port and
        register it to the poller

        :param int socket_type: type of the socket to open
        :param int linger_value: -1 mean wait for receive all msg and block
                                 closing 0 mean hardkill the socket even if msg
                                 are still here.
        :return (zmq.Socket, int): the initialized socket and the port where the
                                   socket is bound
        """
        socket = SafeContext.get_context().socket(socket_type)
        socket.setsockopt(zmq.LINGER, linger_value)
        socket.set_hwm(0)
        port_number = socket.bind_to_random_port(LOCAL_ADDR)
        self.poller.register(socket, zmq.POLLIN)
        self.logger.debug("bind to " + LOCAL_ADDR + ':' + str(port_number))
        return (socket, port_number) 
开发者ID:powerapi-ng,项目名称:powerapi,代码行数:21,代码来源:socket_interface.py

示例5: connect_data

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def connect_data(self):
        """
        Connect to the pull socket of this actor

        Open a push socket on the process that want to communicate with this
        actor

        this method shouldn't be called if socket interface was not initialized
        with the setup method
        """

        if self.pull_socket_address is None:
            self._values_available.wait()
            self.pull_socket_address = LOCAL_ADDR + ':' + str(self._pull_port.value)
            self.control_socket_address = LOCAL_ADDR + ':' + str(self._ctrl_port.value)

        self.push_socket = SafeContext.get_context().socket(zmq.PUSH)
        self.push_socket.setsockopt(zmq.LINGER, -1)
        self.push_socket.set_hwm(0)
        self.push_socket.connect(self.pull_socket_address)
        self.logger.debug("connected data to %s" % (self.pull_socket_address)) 
开发者ID:powerapi-ng,项目名称:powerapi,代码行数:23,代码来源:socket_interface.py

示例6: connect_control

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def connect_control(self):
        """
        Connect to the control socket of this actor

        Open a pair socket on the process that want to control this actor
        this method shouldn't be called if socket interface was not initialized
        with the setup method
        """
        if self.pull_socket_address is None:
            self._values_available.wait()
            self.pull_socket_address = LOCAL_ADDR + ':' + str(self._pull_port.value)
            self.control_socket_address = LOCAL_ADDR + ':' + str(self._ctrl_port.value)

        self.control_socket = SafeContext.get_context().socket(zmq.PAIR)
        self.control_socket.setsockopt(zmq.LINGER, 0)
        self.control_socket.set_hwm(0)
        self.control_socket.connect(self.control_socket_address)
        self.logger.debug("connected control to %s" % (self.control_socket_address)) 
开发者ID:powerapi-ng,项目名称:powerapi,代码行数:20,代码来源:socket_interface.py

示例7: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def __init__(
        self, topic, address="tcp://127.0.0.1:5559", serializer="pickle", wait=0
    ):
        """Create a publisher"""
        self._topic = topic.encode("utf-8")
        self._serializer = getattr(timeflux.core.message, serializer + "_serialize")
        try:
            context = zmq.Context.instance()
            self._socket = context.socket(zmq.PUB)
            self._socket.setsockopt(zmq.LINGER, 0)
            self._socket.connect(address)
        except zmq.ZMQError as e:
            self.logger.error(e)

        # Quick fix to the slow joiner syndrome
        # TODO: remove when Last Value Caching is implemented
        # Wait for subscribers to connect
        # http://zguide.zeromq.org/page%3aall#Getting-the-Message-Out
        # http://zguide.zeromq.org/page%3aall#Node-Coordination
        # http://zguide.zeromq.org/page%3aall#Last-Value-Caching
        # https://stackoverflow.com/questions/30864145/zmq-no-subscription-message-on-xpub-socket-for-multiple-subscribers-last-value
        time.sleep(wait) 
开发者ID:timeflux,项目名称:timeflux,代码行数:24,代码来源:zmq.py

示例8: init_mb_sock

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def init_mb_sock(self, port, data_hwm=10):
        """
        Initialize the mini-batch data socket.

        Parameters
        ----------
        port : int
           The tcp port to reach the mini-batch server on.
        data_hwm : int, optional
           High water mark, see pyzmq docs.

        .. note::
           This must be called before using :meth:`recv_mb`.

        """
        self.asocket = self.context.socket(zmq.PULL)
        self.asocket.setsockopt(zmq.LINGER, 0)
        self.asocket.set_hwm(data_hwm)
        self.asocket.connect("tcp://localhost:{}".format(port))

        self.apoller = zmq.Poller()
        self.apoller.register(self.asocket, zmq.POLLIN) 
开发者ID:mila-iqia,项目名称:platoon,代码行数:24,代码来源:worker.py

示例9: _init_control_socket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def _init_control_socket(self, port):
        """
        Initialize control socket.

        Parameters
        ---------
        port : int
          The tcp port where the control master is listening at.

        .. note::
           This must be called before using :meth:`send_req`.

        """
        self.csocket = self.context.socket(zmq.REQ)
        self.csocket.setsockopt(zmq.LINGER, 0)
        self.csocket.connect('tcp://localhost:{}'.format(port))

        self.cpoller = zmq.Poller()
        self.cpoller.register(self.csocket, zmq.POLLIN)

################################################################################
#                            Collectives Interface                             #
################################################################################ 
开发者ID:mila-iqia,项目名称:platoon,代码行数:25,代码来源:worker.py

示例10: test_send_message_conn_error

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def test_send_message_conn_error(self):
        client = ZeroMQClient("tcp://localhost:5555")
        # Set timeouts
        client.socket.setsockopt(zmq.RCVTIMEO, 5)
        client.socket.setsockopt(zmq.SNDTIMEO, 5)
        client.socket.setsockopt(zmq.LINGER, 5)
        with pytest.raises(zmq.error.ZMQError):
            client.send_message(str(Request("go")), response_expected=True) 
开发者ID:bcb,项目名称:jsonrpcclient,代码行数:10,代码来源:test_zeromq_client.py

示例11: main

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def main() -> None:
    logging.basicConfig(level=logging.INFO)

    LEVELS = {
        "nano": 0,
        "mini": 1,
        "heavyduty": 2,
    }

    parser = argparse.ArgumentParser(description="Simple benchmark utility.")
    parser.add_argument(
        "--ursadb",
        help="URL of the ursadb instance.",
        default="tcp://localhost:9281",
    )
    parser.add_argument(
        "--level",
        help="How hard should the tests be.",
        choices=LEVELS.keys(),
        default="heavyduty",
    )

    args = parser.parse_args()
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.setsockopt(zmq.LINGER, 0)
    socket.connect(args.ursadb)

    level = LEVELS[args.level]
    if level >= 0:
        nano(socket)
    if level >= 1:
        mini(socket)
    if level >= 2:
        heavyduty(socket) 
开发者ID:CERT-Polska,项目名称:mquery,代码行数:37,代码来源:nanobench.py

示例12: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def run(engine, source_name, server_address, all_responses_required=False,
        timeout=TEN_SECONDS, request_retries=REQUEST_RETRIES):
    context = zmq.Context()

    while request_retries > 0:
        socket = context.socket(zmq.REQ)
        socket.connect(server_address)
        from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
        from_standalone_engine.welcome.source_name = source_name
        from_standalone_engine.welcome.all_responses_required = (
            all_responses_required)
        socket.send(from_standalone_engine.SerializeToString())
        logger.info('Sent welcome message to server')

        while True:
            if socket.poll(timeout) == 0:
                logger.warning('No response from server')
                socket.setsockopt(zmq.LINGER, 0)
                socket.close()
                request_retries -= 1
                break

            message_from_server = socket.recv()
            if message_from_server == network_engine.HEARTBEAT:
                socket.send(network_engine.HEARTBEAT)
                continue

            input_frame = gabriel_pb2.InputFrame()
            input_frame.ParseFromString(message_from_server)
            result_wrapper = engine.handle(input_frame)

            from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
            from_standalone_engine.result_wrapper.CopyFrom(result_wrapper)
            socket.send(from_standalone_engine.SerializeToString())

    logger.warning('Ran out of retires. Abandoning server connection.') 
开发者ID:cmusatyalab,项目名称:gabriel,代码行数:38,代码来源:engine_runner.py

示例13: test_bad_sockopts

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def test_bad_sockopts(self):
        """Test that appropriate errors are raised on bad socket options"""
        s = self.context.socket(zmq.PUB)
        self.sockets.append(s)
        s.setsockopt(zmq.LINGER, 0)
        # unrecognized int sockopts pass through to libzmq, and should raise EINVAL
        self.assertRaisesErrno(zmq.EINVAL, s.setsockopt, 9999, 5)
        self.assertRaisesErrno(zmq.EINVAL, s.getsockopt, 9999)
        # but only int sockopts are allowed through this way, otherwise raise a TypeError
        self.assertRaises(TypeError, s.setsockopt, 9999, b"5")
        # some sockopts are valid in general, but not on every socket:
        self.assertRaisesErrno(zmq.EINVAL, s.setsockopt, zmq.SUBSCRIBE, b'hi') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:test_socket.py

示例14: test_sockopt_roundtrip

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def test_sockopt_roundtrip(self):
        "test set/getsockopt roundtrip."
        p = self.context.socket(zmq.PUB)
        self.sockets.append(p)
        p.setsockopt(zmq.LINGER, 11)
        self.assertEqual(p.getsockopt(zmq.LINGER), 11) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_socket.py

示例15: test_attr

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import LINGER [as 别名]
def test_attr(self):
        """set setting/getting sockopts as attributes"""
        s = self.context.socket(zmq.DEALER)
        self.sockets.append(s)
        linger = 10
        s.linger = linger
        self.assertEqual(linger, s.linger)
        self.assertEqual(linger, s.getsockopt(zmq.LINGER))
        self.assertEqual(s.fd, s.getsockopt(zmq.FD)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_socket.py


注:本文中的zmq.LINGER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。