Пример #1
0
    def on_recv(self, callback, copy=True):
        """Register a callback for when a message is ready to recv.
        
        There can be only one callback registered at a time, so each
        call to `on_recv` replaces previously registered callbacks.
        
        on_recv(None) disables recv event polling.
        
        Use on_recv_stream(callback) instead, to register a callback that will receive
        both this ZMQStream and the message, instead of just the message.
        
        Parameters
        ----------
        
        callback : callable
            callback must take exactly one argument, which will be a
            list, as returned by socket.recv_multipart()
            if callback is None, recv callbacks are disabled.
        copy : bool
            copy is passed directly to recv, so if copy is False,
            callback will receive Message objects. If copy is True,
            then callback will receive bytes/str objects.
        
        Returns : None
        """

        self._check_closed()
        assert callback is None or callable(callback)
        self._recv_callback = stack_context.wrap(callback)
        self._recv_copy = copy
        if callback is None:
            self._drop_io_state(self.io_loop.READ)
        else:
            self._add_io_state(self.io_loop.READ)
 def on_recv(self, callback, copy=True):
     """Register a callback for when a message is ready to recv.
     
     There can be only one callback registered at a time, so each
     call to `on_recv` replaces previously registered callbacks.
     
     on_recv(None) disables recv event polling.
     
     Use on_recv_stream(callback) instead, to register a callback that will receive
     both this ZMQStream and the message, instead of just the message.
     
     Parameters
     ----------
     
     callback : callable
         callback must take exactly one argument, which will be a
         list, as returned by socket.recv_multipart()
         if callback is None, recv callbacks are disabled.
     copy : bool
         copy is passed directly to recv, so if copy is False,
         callback will receive Message objects. If copy is True,
         then callback will receive bytes/str objects.
     
     Returns : None
     """
     
     self._check_closed()
     assert callback is None or callable(callback)
     self._recv_callback = stack_context.wrap(callback)
     self._recv_copy = copy
     if callback is None:
         self._drop_io_state(self.io_loop.READ)
     else:
         self._add_io_state(self.io_loop.READ)
Пример #3
0
    def __init__(self, m2req, stream, request_callback, no_keep_alive=False,
            xheaders=False):
        self.m2req = m2req
        self.stream = stream
        self.request_callback = request_callback
        self.no_keep_alive = no_keep_alive
        self.xheaders = xheaders

        self._request = None
        self._request_finished = False

        self._execute = stack_context.wrap(self._begin_request)
        self._execute()
Пример #4
0
    def __init__(self,
                 m2req,
                 stream,
                 request_callback,
                 no_keep_alive=False,
                 xheaders=False):
        self.m2req = m2req
        self.stream = stream
        self.request_callback = request_callback
        self.no_keep_alive = no_keep_alive
        self.xheaders = xheaders

        self._request = None
        self._request_finished = False

        self._execute = stack_context.wrap(self._begin_request)
        self._execute()
Пример #5
0
    def on_send(self, callback):
        """Register a callback to be called on each send
        
        There will be two arguments::
        
            callback(msg, status)
        
        * `msg` will be the list of sendable objects that was just sent
        * `status` will be the return result of socket.send_multipart(msg) -
          MessageTracker or None.
        
        Non-copying sends return a MessageTracker object whose
        `done` attribute will be True when the send is complete.
        This allows users to track when an object is safe to write to
        again.
        
        The second argument will always be None if copy=True
        on the send.
        
        Use on_send_stream(callback) to register a callback that will be passed
        this ZMQStream as the first argument, in addition to the other two.
        
        on_send(None) disables recv event polling.
        
        Parameters
        ----------
        
        callback : callable
            callback must take exactly two arguments, which will be
            the message being sent (always a list),
            and the return result of socket.send_multipart(msg) -
            MessageTracker or None.
            
            if callback is None, send callbacks are disabled.
        """

        self._check_closed()
        assert callback is None or callable(callback)
        self._send_callback = stack_context.wrap(callback)
 def on_send(self, callback):
     """Register a callback to be called on each send
     
     There will be two arguments::
     
         callback(msg, status)
     
     * `msg` will be the list of sendable objects that was just sent
     * `status` will be the return result of socket.send_multipart(msg) -
       MessageTracker or None.
     
     Non-copying sends return a MessageTracker object whose
     `done` attribute will be True when the send is complete.
     This allows users to track when an object is safe to write to
     again.
     
     The second argument will always be None if copy=True
     on the send.
     
     Use on_send_stream(callback) to register a callback that will be passed
     this ZMQStream as the first argument, in addition to the other two.
     
     on_send(None) disables recv event polling.
     
     Parameters
     ----------
     
     callback : callable
         callback must take exactly two arguments, which will be
         the message being sent (always a list),
         and the return result of socket.send_multipart(msg) -
         MessageTracker or None.
         
         if callback is None, send callbacks are disabled.
     """
     
     self._check_closed()
     assert callback is None or callable(callback)
     self._send_callback = stack_context.wrap(callback)
Пример #7
0
 def set_close_callback(self, callback):
     """Call the given callback when the stream is closed."""
     self._close_callback = stack_context.wrap(callback)
 def set_close_callback(self, callback):
     """Call the given callback when the stream is closed."""
     self._close_callback = stack_context.wrap(callback)