Timing out futures: f_timeout, TimeoutExecutor¶
Futures API¶
- more_executors.f_timeout(future, timeout)¶
Wrap a future to cancel it after a timeout is reached.
Signature:
Future<X>, float ⟶ Future<X>- Parameters
- Returns
FutureA wrapped version of
futurewhich may be cancelled if the future has not completed withintimeoutseconds.Note: only a single attempt is made to cancel the future, and there is no guarantee that the cancel will succeed.
New in version 1.19.0.
Executors API¶
- class more_executors.TimeoutExecutor(delegate, timeout, logger=None, name='default')¶
An executor which delegates to another executor while applying a timeout to each returned future.
For any futures returned by this executor, if the future hasn’t completed approximately within timeout seconds of its creation, an attempt will be made to cancel the future.
Note that only a single attempt is made to cancel any future, and there is no guarantee that this will succeed.
New in version 1.7.0.
- Parameters
delegate (Executor) – an executor to which callables are submitted
timeout (float) – timeout (in seconds) after which
concurrent.futures.Future.cancel()will be invoked on any generated future which has not completedlogger (Logger) – a logger used for messages from this executor
name (str) – a name for this executor
Changed in version 2.7.0: Introduced
name.- submit_timeout(timeout, fn, *args, **kwargs)¶
Like
submit(fn, *args, **kwargs), but uses the specified timeout rather than this executor’s default.New in version 1.19.0.
- classmethod Executors.with_timeout(executor, timeout, logger=None)¶
- Returns
a new executor which will attempt to cancel any futures if they’ve not completed within the given timeout.
- Return type
New in version 1.7.0.