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
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
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
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
def fn(): return Executors.sync().with_poll(poll_noop).with_throttle(2)
def fn(): return Executors.sync().with_timeout(30.0)
def fn(): return Executors.sync().with_throttle(2)
def fn(): return Executors.sync().with_poll(poll_noop)
def ctor_with_retry(): return Executors.sync().with_retry
def test_with_throttle(): assert_that(Executors.sync().with_throttle(4), instance_of(ThrottleExecutor))
def test_with_throttle(): assert_that( Executors.sync(name="throttle-test").with_throttle(4, block=True), instance_of(ThrottleExecutor), )