本文整理汇总了Python中qi.Promise.future方法的典型用法代码示例。如果您正苦于以下问题:Python Promise.future方法的具体用法?Python Promise.future怎么用?Python Promise.future使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qi.Promise
的用法示例。
在下文中一共展示了Promise.future方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_future_unwrap_cancel
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_unwrap_cancel():
prom = Promise()
future = prom.future().unwrap()
future.cancel()
assert prom.isCancelRequested()
nested = Promise()
prom.setValue(nested.future())
# TODO add some sync-ness to remove those time.sleep :(
time.sleep(0.1)
assert nested.isCancelRequested()
nested.setCanceled()
time.sleep(0.1)
assert future.isCanceled()
示例2: test_future_wait
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_wait():
p = Promise()
f = p.future()
threading.Thread(target=waitSetValue, args=[p, 0.1]).start()
assert f.isFinished() is False
assert f.value() == "mjolk"
assert f.isFinished() is True
示例3: test_future_no_timeout
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_no_timeout():
p = Promise()
f = p.future()
threading.Thread(target=waitSetValue, args=[p]).start()
# 1sec to be secure
assert f.value(timeout=1000) == "mjolk"
assert f.hasError() is False
示例4: test_future_cancel_exception
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_cancel_exception():
def throw(promise):
time.sleep(0.01)
raise Exception("plop")
p = Promise(throw)
f = p.future()
f.cancel()
示例5: test_future_timeout_immediate
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_timeout_immediate():
p = Promise()
f = p.future()
threading.Thread(target=waitSetValue, args=[p, 1]).start()
try:
f.value(timeout=0)
except RuntimeError:
pass
示例6: test_future_two_callbacks
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_two_callbacks():
result1 = Promise()
result2 = Promise()
def callback1(f):
global called1
called1 = "1"
result1.setValue("bim")
def callback2(f):
global called2
called2 = "2"
result2.setValue("bim")
p = Promise()
f = p.future()
f.addCallback(callback1)
f.addCallback(callback2)
p.setValue(42)
result1.future().wait(1000)
result2.future().wait(1000)
assert result1.future().hasValue(0)
assert result2.future().hasValue(0)
assert called1 == "1"
assert called2 == "2"
示例7: test_future_many_callback
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_many_callback(nbr_fut = 10000):
def callback(f):
pass
for _ in range(nbr_fut):
p = Promise()
f = p.future()
f.addCallback(callback)
p.setValue(0)
示例8: test_future_exception
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_exception():
p = Promise()
f = p.future()
def raising(f):
raise Exception("oops")
f.addCallback(raising)
p.setValue(42)
示例9: test_future_callback_noargs
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_callback_noargs():
def callback():
pass
p = Promise()
f = p.future()
f.addCallback(callback)
p.setValue("segv?")
assert not f.isCanceled()
assert f.isFinished()
示例10: test_many_futures_create
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_many_futures_create():
def wait(p):
time.sleep(1)
p = Promise(wait)
fs = [p.future() for _ in range(100)]
p.setValue(1337)
for f in fs:
assert f.hasValue()
assert f.value() == 1337
示例11: test_future_error
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_error():
p = Promise()
p.setError("woops")
f = p.future()
assert f.hasError() is True
assert f.error() == "woops"
try:
f.value()
except RuntimeError:
pass
示例12: test_future_timeout
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_timeout():
p = Promise()
f = p.future()
threading.Thread(target=waitSetValue, args=[p, 1]).start()
try:
# 10ms - 3ms
f.value(timeout=8)
except RuntimeError:
pass
assert f.hasError() is False
示例13: test_future_callback
# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import future [as 别名]
def test_future_callback():
result = Promise()
def callback(f):
global called
assert f.isRunning() is False
assert f.value() == 1337
assert called is False
called = "aight"
result.setValue("bim")
p = Promise()
f = p.future()
f.addCallback(callback)
p.setValue(1337)
result.future().wait(1000)
assert result.future().hasValue(0)
assert called == "aight"
assert not f.isCanceled()
assert f.isFinished()