當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。