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


Python qi.Promise类代码示例

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


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

示例1: test_promise_re_set

def test_promise_re_set():
    p = Promise()
    p.setValue(42)
    try:
        p.setValue(42)
    except RuntimeError:
        pass
开发者ID:aldebaran,项目名称:libqi-python,代码行数:7,代码来源:test_promise.py

示例2: test_future_wait

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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:7,代码来源:test_promise.py

示例3: test_future_no_timeout

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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:7,代码来源:test_promise.py

示例4: test_future_cancel_exception

def test_future_cancel_exception():
    def throw(promise):
        time.sleep(0.01)
        raise Exception("plop")

    p = Promise(throw)
    f = p.future()
    f.cancel()
开发者ID:aldebaran,项目名称:libqi-python,代码行数:8,代码来源:test_promise.py

示例5: test_future_timeout_immediate

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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:8,代码来源:test_promise.py

示例6: test_many_futures_create

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,代码行数:9,代码来源:test_promise.py

示例7: test_future_exception

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,代码行数:9,代码来源:test_promise.py

示例8: test_future_many_callback

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,代码行数:9,代码来源:test_promise.py

示例9: test_future_callback_noargs

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,代码行数:9,代码来源:test_promise.py

示例10: test_future_timeout

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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:10,代码来源:test_promise.py

示例11: test_future_error

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
开发者ID:aldebaran,项目名称:libqi-python,代码行数:10,代码来源:test_promise.py

示例12: test_future_andthen

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,代码行数:13,代码来源:test_promise.py

示例13: test_future_then

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,代码行数:14,代码来源:test_promise.py

示例14: test_future_then_throw

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,代码行数:14,代码来源:test_promise.py

示例15: test_future_unwrap_cancel

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,代码行数:14,代码来源:test_promise.py


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