本文整理汇总了Python中concurrent.futures._set_result_unless_cancelled方法的典型用法代码示例。如果您正苦于以下问题:Python futures._set_result_unless_cancelled方法的具体用法?Python futures._set_result_unless_cancelled怎么用?Python futures._set_result_unless_cancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类concurrent.futures
的用法示例。
在下文中一共展示了futures._set_result_unless_cancelled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sleep
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import _set_result_unless_cancelled [as 别名]
def sleep(delay, result=None, *, loop=None):
"""Coroutine that completes after a given time (in seconds)."""
if delay <= 0:
await __sleep0()
return result
if loop is None:
loop = events.get_event_loop()
future = loop.create_future()
h = loop.call_later(delay,
futures._set_result_unless_cancelled,
future, result)
try:
return await future
finally:
h.cancel()
示例2: sleep
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import _set_result_unless_cancelled [as 别名]
def sleep(delay, result=None, *, loop=None):
"""Coroutine that completes after a given time (in seconds)."""
if delay == 0:
yield
return result
if loop is None:
loop = events.get_event_loop()
future = loop.create_future()
h = future._loop.call_later(delay,
futures._set_result_unless_cancelled,
future, result)
try:
return (yield from future)
finally:
h.cancel()
示例3: sleep
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import _set_result_unless_cancelled [as 别名]
def sleep(delay, result=None, *, loop=None):
"""Coroutine that completes after a given time (in seconds)."""
if delay == 0:
yield
return result
future = futures.Future(loop=loop)
h = future._loop.call_later(delay,
futures._set_result_unless_cancelled,
future, result)
try:
return (yield from future)
finally:
h.cancel()
示例4: test_set_result_unless_cancelled
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import _set_result_unless_cancelled [as 别名]
def test_set_result_unless_cancelled(self):
from asyncio import futures
fut = asyncio.Future(loop=self.loop)
fut.cancel()
futures._set_result_unless_cancelled(fut, 2)
self.assertTrue(fut.cancelled())
示例5: test_set_result_unless_cancelled
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import _set_result_unless_cancelled [as 别名]
def test_set_result_unless_cancelled(self):
fut = self._new_future(loop=self.loop)
fut.cancel()
futures._set_result_unless_cancelled(fut, 2)
self.assertTrue(fut.cancelled())