def test_throttle_dynamic_raises_cannot_construct():
    """Can't make a ThrottleExecutor if count immediately raises"""

    error = RuntimeError("oops")

    def raise_error():
        raise error

    with pytest.raises(RuntimeError) as exc_info:
        Executors.sync().with_throttle(count=raise_error)
    assert exc_info.value is error
예제 #2
0
def test_no_rebind():
    bound = Executors.sync().bind(mult10)

    try:
        bound.bind(mult2)
        raise AssertionError("Chained bind should have failed!")  # pragma: no cover
    except AttributeError:
        pass
예제 #3
0
def timeout_executor():
    global EXECUTOR_REF  # pylint: disable=global-statement
    with LOCK:
        executor = EXECUTOR_REF and EXECUTOR_REF()
        if not executor:
            executor = Executors.sync().with_flat_map(
                lambda x: x).with_timeout(None)
            EXECUTOR_REF = weakref.ref(executor)
        return executor
예제 #4
0
def timeout_executor():
    global EXECUTOR_REF  # pylint: disable=global-statement
    with LOCK:
        executor = EXECUTOR_REF and EXECUTOR_REF()
        if not executor:
            # TODO: consider rethinking this and keeping one
            # executor alive until atexit() instead.
            executor = (Executors.sync(
                name="internal").with_flat_map(lambda x: x).with_timeout(None))
            EXECUTOR_REF = weakref.ref(executor)
        return executor
예제 #5
0
 def fn():
     return Executors.sync().with_poll(poll_noop).with_throttle(2)
예제 #6
0
 def fn():
     return Executors.sync().with_timeout(30.0)
예제 #7
0
 def fn():
     return Executors.sync().with_throttle(2)
예제 #8
0
 def fn():
     return Executors.sync().with_poll(poll_noop)
예제 #9
0
def ctor_with_retry():
    return Executors.sync().with_retry
예제 #10
0
def test_with_throttle():
    assert_that(Executors.sync().with_throttle(4),
                instance_of(ThrottleExecutor))
예제 #11
0
def test_with_throttle():
    assert_that(
        Executors.sync(name="throttle-test").with_throttle(4, block=True),
        instance_of(ThrottleExecutor),
    )