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


Python Future.cancel方法代码示例

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


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

示例1: get

# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import cancel [as 别名]
 def get(self):
     """Remove and return an item from the channel.
     If channel is empty, wait until an item is available.
     This method is a coroutine.
     """
     while self.empty() and not self._close.is_set():
         getter = Future(loop=self._loop)
         self._getters.append(getter)
         try:
             yield from getter
         except ChannelClosed:
             raise
         except:
             getter.cancel()  # Just in case getter is not done yet.
             if not self.empty() and not getter.cancelled():
                 # We were woken up by put_nowait(), but can't take
                 # the call.  Wake up the next in line.
                 self._wakeup_next(self._getters)
             raise
     return self.get_nowait()
开发者ID:tbug,项目名称:aiochannel,代码行数:22,代码来源:channel.py

示例2: put

# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import cancel [as 别名]
 def put(self, item):
     """Put an item into the channel.
     If the channel is full, wait until a free
     slot is available before adding item.
     If the channel is closed or closing, raise ChannelClosed.
     This method is a coroutine.
     """
     while self.full() and not self._close.is_set():
         putter = Future(loop=self._loop)
         self._putters.append(putter)
         try:
             yield from putter
         except ChannelClosed:
             raise
         except:
             putter.cancel()  # Just in case putter is not done yet.
             if not self.full() and not putter.cancelled():
                 # We were woken up by get_nowait(), but can't take
                 # the call.  Wake up the next in line.
                 self._wakeup_next(self._putters)
             raise
     return self.put_nowait(item)
开发者ID:tbug,项目名称:aiochannel,代码行数:24,代码来源:channel.py


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