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


Python zmq.DONTWAIT属性代码示例

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


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

示例1: remote_recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def remote_recv(self, _socket):
        
        if self._PULL_SOCKET_STATUS['state'] == True:
            try:
                msg = _socket.recv_string(zmq.DONTWAIT)
                return msg
            except zmq.error.Again:
                print("\nResource timeout.. please try again.")
                sleep(self._sleep_delay)
        else:
            print('\r[KERNEL] NO HANDSHAKE ON PULL SOCKET.. Cannot READ data', end='', flush=True)
            
        return None
        
    ##########################################################################
    
    # Convenience functions to permit easy trading via underlying functions.
    
    # OPEN ORDER 
开发者ID:darwinex,项目名称:dwx-zeromq-connector,代码行数:21,代码来源:DWX_ZeroMQ_Connector_v2_0_1_RC8.py

示例2: remote_recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def remote_recv(self, _socket):
        
        try:
            msg = _socket.recv_string(zmq.DONTWAIT)
            return msg
        except zmq.error.Again:
            print("\nResource timeout.. please try again.")
            sleep(0.000001)
            
        return None
        
    ##########################################################################
    
    # Convenience functions to permit easy trading via underlying functions.
    
    # OPEN ORDER 
开发者ID:darwinex,项目名称:dwx-zeromq-connector,代码行数:18,代码来源:DWX_ZeroMQ_Connector_v2_0_2_RC1.py

示例3: recv_params_from_learner

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def recv_params_from_learner(self):
        """Get new params and sync. return True if success, False otherwise."""
        received = False
        try:
            new_params_id = self.sub_socket.recv(zmq.DONTWAIT)
            received = True
        except zmq.Again:
            # Although learner doesn't send params, don't wait
            pass

        if received:
            new_param_info = pa.deserialize(new_params_id)
            update_step, new_params = new_param_info
            self.update_step = update_step
            self.worker.synchronize(new_params)

            # Add new entry for scores dict
            self.scores[self.update_step] = [] 
开发者ID:medipixel,项目名称:rl_algorithms,代码行数:20,代码来源:worker.py

示例4: recv_worker_data

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def recv_worker_data(self):
        """Receive replay data from worker and incorporate to buffer."""
        received = False
        try:
            new_replay_data_id = self.pull_socket.recv(zmq.DONTWAIT)
            received = True
        except zmq.Again:
            pass

        if received:
            new_replay_data = pa.deserialize(new_replay_data_id)
            experience, priorities = new_replay_data
            for idx in range(len(experience["states"])):
                transition = (
                    experience["states"][idx],
                    experience["actions"][idx],
                    experience["rewards"][idx],
                    experience["next_states"][idx],
                    experience["dones"][idx],
                )
                self.buffer.add(transition)
                self.buffer.update_priorities([len(self.buffer) - 1], priorities[idx]) 
开发者ID:medipixel,项目名称:rl_algorithms,代码行数:24,代码来源:wrapper.py

示例5: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def run(self):
        if self.should_stop:  # early exit
            return 1

        context = zmq.Context()
        socket = context.socket(zmq.SUB)

        logger.info(f"subscribing to events from {self.socket_uri}…")
        socket.connect(self.socket_uri)
        for event in self.events:
            logger.debug(f".. {event}")
            socket.setsockopt_string(zmq.SUBSCRIBE, event)

        while not self.should_stop:
            try:
                received_string = socket.recv_string(zmq.DONTWAIT)
                self.handle_broadcast_event(received_string)
            except zmq.Again:
                pass

            if self.should_poll:
                self.sync_tasks_and_containers()
                self.poll()
            else:
                self.sleep() 
开发者ID:openzim,项目名称:zimfarm,代码行数:27,代码来源:worker.py

示例6: send_message

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def send_message(socket, cmd, data, blocking=True):
        flags = 0 if blocking else zmq.DONTWAIT
        socket.send_multipart([cmd, data], flags=flags) 
开发者ID:RobinDavid,项目名称:idasec,代码行数:5,代码来源:broker.py

示例7: _add_recv_event

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def _add_recv_event(self, kind, kwargs=None, future=None):
        """Add a recv event, returning the corresponding Future"""
        f = future or self._Future()
        if kind.startswith('recv') and kwargs.get('flags', 0) & _zmq.DONTWAIT:
            # short-circuit non-blocking calls
            recv = getattr(self._shadow_sock, kind)
            try:
                r = recv(**kwargs)
            except Exception as e:
                f.set_exception(e)
            else:
                f.set_result(r)
            return f

        # we add it to the list of futures before we add the timeout as the
        # timeout will remove the future from recv_futures to avoid leaks
        self._recv_futures.append(
            _FutureEvent(f, kind, kwargs, msg=None)
        )

        # Don't let the Future sit in _recv_events after it's done
        f.add_done_callback(lambda f: self._remove_finished_future(f, self._recv_futures))

        if hasattr(_zmq, 'RCVTIMEO'):
            timeout_ms = self._shadow_sock.rcvtimeo
            if timeout_ms >= 0:
                self._add_timeout(f, timeout_ms * 1e-3)

        if self._shadow_sock.EVENTS & POLLIN:
            # recv immediately, if we can
            self._handle_recv()
        if self._recv_futures:
            self._add_io_state(POLLIN)
        return f 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:36,代码来源:_future.py

示例8: _add_send_event

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def _add_send_event(self, kind, msg=None, kwargs=None, future=None):
        """Add a send event, returning the corresponding Future"""
        f = future or self._Future()
        if kind.startswith('send') and kwargs.get('flags', 0) & _zmq.DONTWAIT:
            # short-circuit non-blocking calls
            send = getattr(self._shadow_sock, kind)
            try:
                r = send(msg, **kwargs)
            except Exception as e:
                f.set_exception(e)
            else:
                f.set_result(r)
            return f

        # we add it to the list of futures before we add the timeout as the
        # timeout will remove the future from recv_futures to avoid leaks
        self._send_futures.append(
            _FutureEvent(f, kind, kwargs=kwargs, msg=msg)
        )
        # Don't let the Future sit in _send_futures after it's done
        f.add_done_callback(lambda f: self._remove_finished_future(f, self._send_futures))

        if hasattr(_zmq, 'SNDTIMEO'):
            timeout_ms = self._shadow_sock.sndtimeo
            if timeout_ms >= 0:
                self._add_timeout(f, timeout_ms * 1e-3)

        if self._shadow_sock.EVENTS & POLLOUT:
            # send immediately if we can
            self._handle_send()
        if self._send_futures:
            self._add_io_state(POLLOUT)
        return f 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:35,代码来源:_future.py

示例9: _handle_recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def _handle_recv(self):
        """Handle recv events"""
        if not self._shadow_sock.EVENTS & POLLIN:
            # event triggered, but state may have been changed between trigger and callback
            return
        f = None
        while self._recv_futures:
            f, kind, kwargs, _ = self._recv_futures.popleft()
            f._pyzmq_popped = True
            # skip any cancelled futures
            if f.done():
                f = None
            else:
                break
        
        if not self._recv_futures:
            self._drop_io_state(POLLIN)
        
        if f is None:
            return
        
        if kind == 'poll':
            # on poll event, just signal ready, nothing else.
            f.set_result(None)
            return
        elif kind == 'recv_multipart':
            recv = self._shadow_sock.recv_multipart
        elif kind == 'recv':
            recv = self._shadow_sock.recv
        else:
            raise ValueError("Unhandled recv event type: %r" % kind)
        
        kwargs['flags'] |= _zmq.DONTWAIT
        try:
            result = recv(**kwargs)
        except Exception as e:
            f.set_exception(e)
        else:
            f.set_result(result) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:41,代码来源:_future.py

示例10: _handle_send

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def _handle_send(self):
        if not self._shadow_sock.EVENTS & POLLOUT:
            # event triggered, but state may have been changed between trigger and callback
            return
        f = None
        while self._send_futures:
            f, kind, kwargs, msg = self._send_futures.popleft()
            f._pyzmq_popped = True
            # skip any cancelled futures
            if f.done():
                f = None
            else:
                break
        
        if not self._send_futures:
            self._drop_io_state(POLLOUT)

        if f is None:
            return
        
        if kind == 'poll':
            # on poll event, just signal ready, nothing else.
            f.set_result(None)
            return
        elif kind == 'send_multipart':
            send = self._shadow_sock.send_multipart
        elif kind == 'send':
            send = self._shadow_sock.send
        else:
            raise ValueError("Unhandled send event type: %r" % kind)
        
        kwargs['flags'] |= _zmq.DONTWAIT
        try:
            result = send(msg, **kwargs)
        except Exception as e:
            f.set_exception(e)
        else:
            f.set_result(result)
    
    # event masking from ZMQStream 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:42,代码来源:_future.py

示例11: test_recv_dontwait

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def test_recv_dontwait(self):
        @asyncio.coroutine
        def test():
            push, pull = self.create_bound_pair(zmq.PUSH, zmq.PULL)
            f = pull.recv(zmq.DONTWAIT)
            with self.assertRaises(zmq.Again):
                yield from f
            yield from push.send(b'ping')
            yield from pull.poll() # ensure message will be waiting
            f = pull.recv(zmq.DONTWAIT)
            assert f.done()
            msg = yield from f
            self.assertEqual(msg, b'ping')
        self.loop.run_until_complete(test()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:_test_asyncio.py

示例12: remote_send

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def remote_send(self, _socket, _data):
        
        if self._PUSH_SOCKET_STATUS['state'] == True:
            try:
                _socket.send_string(_data, zmq.DONTWAIT)
            except zmq.error.Again:
                print("\nResource timeout.. please try again.")
                sleep(self._sleep_delay)
        else:
            print('\n[KERNEL] NO HANDSHAKE ON PUSH SOCKET.. Cannot SEND data')
      
    ########################################################################## 
开发者ID:darwinex,项目名称:dwx-zeromq-connector,代码行数:14,代码来源:DWX_ZeroMQ_Connector_v2_0_1_RC8.py

示例13: remote_send

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def remote_send(self, _socket, _data):
        
        try:
            _socket.send_string(_data, zmq.DONTWAIT)
        except zmq.error.Again:
            print("\nResource timeout.. please try again.")
            sleep(0.000000001)
      
    ########################################################################## 
开发者ID:darwinex,项目名称:dwx-zeromq-connector,代码行数:11,代码来源:DWX_ZeroMQ_Connector_v2_0_2_RC1.py

示例14: _SendItem

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def _SendItem(self, zmq_socket, item, block=True):
    """Attempts to send an item to a ZeroMQ socket.

    Args:
      zmq_socket (zmq.Socket): used to the send the item.
      item (object): sent on the queue. Will be pickled prior to sending.
      block (Optional[bool]): whether the push should be performed in blocking
          or non-blocking mode.

    Returns:
      bool: whether the item was sent successfully.
    """
    try:
      logger.debug('{0:s} sending item'.format(self.name))
      if block:
        zmq_socket.send_pyobj(item)
      else:
        zmq_socket.send_pyobj(item, zmq.DONTWAIT)
      logger.debug('{0:s} sent item'.format(self.name))
      return True

    except zmq.error.Again:
      logger.debug('{0:s} could not send an item'.format(self.name))

    except zmq.error.ZMQError as exception:
      if exception.errno == errno.EINTR:
        logger.error(
            'ZMQ syscall interrupted in {0:s}.'.format(
                self.name))

    return False 
开发者ID:log2timeline,项目名称:plaso,代码行数:33,代码来源:zeromq_queue.py

示例15: recv_log_info

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import DONTWAIT [as 别名]
def recv_log_info(self):
        """Receive info from learner."""
        received = False
        try:
            log_info_id = self.pull_socket.recv(zmq.DONTWAIT)
            received = True
        except zmq.Again:
            pass

        if received:
            self.log_info_queue.append(log_info_id) 
开发者ID:medipixel,项目名称:rl_algorithms,代码行数:13,代码来源:distributed_logger.py


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