當前位置: 首頁>>代碼示例>>Python>>正文


Python Promise.future方法代碼示例

本文整理匯總了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()
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:16,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:9,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:9,代碼來源:test_promise.py

示例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()
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:10,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:10,代碼來源:test_promise.py

示例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"
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:29,代碼來源:test_promise.py

示例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)
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:11,代碼來源:test_promise.py

示例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)
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:11,代碼來源:test_promise.py

示例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()
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:11,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:11,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:12,代碼來源:test_promise.py

示例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
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:12,代碼來源:test_promise.py

示例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()
開發者ID:aldebaran,項目名稱:libqi-python,代碼行數:23,代碼來源:test_promise.py


注:本文中的qi.Promise.future方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。