• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stack_context.wrap函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zmq.eventloop.stack_context.wrap函数的典型用法代码示例。如果您正苦于以下问题:Python wrap函数的具体用法?Python wrap怎么用?Python wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: on_send

 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)
开发者ID:proger,项目名称:pyzmq,代码行数:28,代码来源:zmqstream.py


示例2: on_recv

 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)
开发者ID:HVF,项目名称:pyzmq,代码行数:34,代码来源:zmqstream.py


示例3: on_recv

 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)
开发者ID:proger,项目名称:pyzmq,代码行数:29,代码来源:zmqstream.py


示例4: add_callback

    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()
开发者ID:kyledj,项目名称:pyzmq,代码行数:8,代码来源:ioloop.py


示例5: on_err

 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.
     """
     self._errback = stack_context.wrap(callback)
开发者ID:bwhite,项目名称:pyzmq,代码行数:11,代码来源:zmqstream.py


示例6: add_timeout

    def add_timeout(self, deadline, callback):
        """Calls the given callback at the time deadline from the I/O loop.

        Returns a handle that may be passed to remove_timeout to cancel.

        ``deadline`` may be a number denoting a unix timestamp (as returned
        by ``time.time()`` or a ``datetime.timedelta`` object for a deadline
        relative to the current time.
        """
        timeout = _Timeout(deadline, stack_context.wrap(callback))
        heapq.heappush(self._timeouts, timeout)
        return timeout
开发者ID:actank,项目名称:zmon,代码行数:12,代码来源:ioloop.py


示例7: __init__

    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()
开发者ID:PaulGuo,项目名称:tornadotools,代码行数:13,代码来源:handler.py


示例8: add_timeout

    def add_timeout(self, deadline, callback):
        """Calls the given callback at the time deadline from the I/O loop.

        Returns a handle that may be passed to remove_timeout to cancel.

        ``deadline`` may be a number denoting a unix timestamp (as returned
        by ``time.time()`` or a ``datetime.timedelta`` object for a deadline
        relative to the current time.

        Note that it is not safe to call `add_timeout` from other threads.
        Instead, you must use `add_callback` to transfer control to the
        IOLoop's thread, and then call `add_timeout` from there.
        """
        timeout = _Timeout(deadline, stack_context.wrap(callback))
        heapq.heappush(self._timeouts, timeout)
        return timeout
开发者ID:AndreaCrotti,项目名称:pyzmq,代码行数:16,代码来源:ioloop.py


示例9: add_callback

    def add_callback(self, callback):
        """Calls the given callback on the next I/O loop iteration.

        It is safe to call this method from any thread at any time.
        Note that this is the *only* method in IOLoop that makes this
        guarantee; all other interaction with the IOLoop must be done
        from that IOLoop's thread.  add_callback() may be used to transfer
        control from other threads to the IOLoop's thread.
        """
        with self._callback_lock:
            list_empty = not self._callbacks
            self._callbacks.append(stack_context.wrap(callback))
        if list_empty and thread_get_ident() != self._thread_ident:
            # If we're in the IOLoop's thread, we know it's not currently
            # polling.  If we're not, and we added the first callback to an
            # empty list, we may need to wake it up (it may wake up on its
            # own, but an occasional extra wake is harmless).  Waking
            # up a polling IOLoop is relatively expensive, so we try to
            # avoid it when we can.
            self._waker.wake()
开发者ID:AndreaCrotti,项目名称:pyzmq,代码行数:20,代码来源:ioloop.py


示例10: on_send

 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)
开发者ID:HVF,项目名称:pyzmq,代码行数:39,代码来源:zmqstream.py


示例11: set_close_callback

 def set_close_callback(self, callback):
     """Call the given callback when the stream is closed."""
     self._close_callback = stack_context.wrap(callback)
开发者ID:proger,项目名称:pyzmq,代码行数:3,代码来源:zmqstream.py


示例12: add_handler

 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)
开发者ID:AndreaCrotti,项目名称:pyzmq,代码行数:4,代码来源:ioloop.py


示例13: add_timeout

 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
开发者ID:kyledj,项目名称:pyzmq,代码行数:5,代码来源:ioloop.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python zmqstream.ZMQStream类代码示例发布时间:2022-05-26
下一篇:
Python ioloop.PeriodicCallback类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap