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


Python Promise.setValue方法代码示例

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


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

示例1: test_promise_re_set

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_promise_re_set():
    p = Promise()
    p.setValue(42)
    try:
        p.setValue(42)
    except RuntimeError:
        pass
开发者ID:aldebaran,项目名称:libqi-python,代码行数:9,代码来源:test_promise.py

示例2: test_future_two_callbacks

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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"
开发者ID:aldebaran,项目名称:libqi-python,代码行数:29,代码来源:test_promise.py

示例3: test_future_many_callback

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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)
开发者ID:aldebaran,项目名称:libqi-python,代码行数:11,代码来源:test_promise.py

示例4: test_future_exception

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_exception():
    p = Promise()
    f = p.future()

    def raising(f):
        raise Exception("oops")

    f.addCallback(raising)
    p.setValue(42)
开发者ID:aldebaran,项目名称:libqi-python,代码行数:11,代码来源:test_promise.py

示例5: test_future_callback_noargs

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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()
开发者ID:aldebaran,项目名称:libqi-python,代码行数:11,代码来源:test_promise.py

示例6: test_many_futures_create

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:11,代码来源:test_promise.py

示例7: test_future_andthen

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_andthen():

    def callback(v):
        assert v == 1337
        return 4242

    p = Promise()
    f = p.future()
    f2 = f.andThen(callback)
    p.setValue(1337)
    f2.wait(1000)
    assert f2.isFinished()
    assert f2.value() == 4242
开发者ID:aldebaran,项目名称:libqi-python,代码行数:15,代码来源:test_promise.py

示例8: test_future_unwrap_cancel

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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()
开发者ID:aldebaran,项目名称:libqi-python,代码行数:16,代码来源:test_promise.py

示例9: test_future_then_throw

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_then_throw():

    def callback(f):
        assert f.isRunning() is False
        assert f.value() == 1337
        raise RuntimeError("lol")

    p = Promise()
    f = p.future()
    f2 = f.then(callback)
    p.setValue(1337)
    f2.wait(1000)
    assert f2.isFinished()
    assert f2.error().endswith("RuntimeError: lol\n")
开发者ID:aldebaran,项目名称:libqi-python,代码行数:16,代码来源:test_promise.py

示例10: test_future_then

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_then():

    def callback(f):
        assert f.isRunning() is False
        assert f.value() == 1337
        return 4242

    p = Promise()
    f = p.future()
    f2 = f.then(callback)
    p.setValue(1337)
    f2.wait(1000)
    assert f2.isFinished()
    assert f2.value() == 4242
开发者ID:aldebaran,项目名称:libqi-python,代码行数:16,代码来源:test_promise.py

示例11: test_many_futures_wait_cancel

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_many_futures_wait_cancel():
    def cancel(p):
        try:
            p.setValue("Kappa")
        except:
            pass #ok: cancel called many times

    waiter = Promise();
    ps = [Promise(cancel) for _ in range(50)]
    fs = [p.future() for p in ps]
    for p in ps:
        threading.Thread(target=waiterSetValue, args=[p, waiter.future()]).start()
    # Cancel only one future
    fs[25].cancel()
    waiter.setValue(None)

    for i, f in enumerate(fs):
        if i == 25:
            assert f.value() == "Kappa"
        else:
            assert f.value() == "mjolk"
开发者ID:aldebaran,项目名称:libqi-python,代码行数:23,代码来源:test_promise.py

示例12: test_future_callback

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [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()
开发者ID:aldebaran,项目名称:libqi-python,代码行数:23,代码来源:test_promise.py

示例13: test_future_unwrap_notfuture

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_unwrap_notfuture():
    prom = Promise()
    future = prom.future().unwrap()
    prom.setValue(42)

    assert future.hasError()
开发者ID:aldebaran,项目名称:libqi-python,代码行数:8,代码来源:test_promise.py

示例14: test_future_unwrap

# 需要导入模块: from qi import Promise [as 别名]
# 或者: from qi.Promise import setValue [as 别名]
def test_future_unwrap():
    prom = Promise()
    future = prom.future().unwrap()
    prom.setValue(Future(42))

    assert future.value() == 42
开发者ID:aldebaran,项目名称:libqi-python,代码行数:8,代码来源:test_promise.py


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