コード例 #1
0
ファイル: zmqstream.py プロジェクト: truemped/zerobelt
    def on_send(self, callback):
        """Register a callback to be called on each send
        There will be two arguments: the message being sent (always a list), 
        and the return result of socket.send_multipart(msg).

        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.

        on_send(None) disables recv event polling.

        Parameters
        ----------

        callback : callable
            callback must take exactly two arguments, which will be
            There will be two arguments: 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.
        """
        assert callback is None or callable(callback)
        self._send_callback = stack_context.wrap(callback)
コード例 #2
0
ファイル: zmqstream.py プロジェクト: truemped/zerobelt
    def on_recv(self, callback, copy=True):
        """Register a callback to be called 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.

        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
        """
        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(zmq.POLLIN)
        else:
            self._add_io_state(zmq.POLLIN)
コード例 #3
0
ファイル: ioloop.py プロジェクト: truemped/zerobelt
    def add_callback(self, callback):
        """Calls the given callback on the next I/O loop iteration.

        This is thread safe because set.add is an atomic operation. The rest
        of the API is not thread safe.
        """
        self._callbacks.add(stack_context.wrap(callback))
        self._wake()
コード例 #4
0
ファイル: zmqstream.py プロジェクト: truemped/zerobelt
    def on_err(self, callback):
        """register a callback to be called on POLLERR events
        with no arguments.

        Parameters
        ----------

        callback : callable
            callback will be passed no arguments.
        """
        assert callback is None or callable(callback)
        self._errback = stack_context.wrap(callback)
コード例 #5
0
ファイル: zmqstream.py プロジェクト: truemped/zerobelt
 def set_close_callback(self, callback):
     """Call the given callback when the stream is closed."""
     self._close_callback = stack_context.wrap(callback)
コード例 #6
0
ファイル: ioloop.py プロジェクト: truemped/zerobelt
 def add_timeout(self, deadline, callback):
     """Calls the given callback at the time deadline from the I/O loop."""
     timeout = _Timeout(deadline, stack_context.wrap(callback))
     bisect.insort(self._timeouts, timeout)
     return timeout
コード例 #7
0
ファイル: ioloop.py プロジェクト: truemped/zerobelt
 def add_handler(self, fd, handler, events):
     """Registers the given handler to receive the given events for fd."""
     self._handlers[fd] = stack_context.wrap(handler)
     self._impl.register(fd, events | self.ERROR)