fleche.executor

Executor wrapper that intercepts submit for fleche-decorated functions.

Motivation: users passing a fleche.fleche()-decorated function to executor.submit(...) have to remember to call BoundWrapper.bind() themselves to carry the active cache/metadata state into the worker. They also pay the submit/serialisation cost even when the result is already cached.

wrap_executor() patches the submit method of an executor instance (we cannot subclass, since callers pass us instances of third-party executors) so that:

  • non-fleche callables are forwarded unchanged,

  • fleche callables whose result is already cached are returned via an already-completed Future without touching the executor, and

  • otherwise the call is bound via BoundWrapper.bind() and submitted to the original submit.

Executors that declare their own keyword-only parameters on submit (e.g. resources= or resource_dict=) have those split off from the caller’s **kwargs and forwarded to the underlying submit while the remaining keyword arguments are bound as part of the function payload.

Functions

wrap_executor(executor)

Monkey-patch executor.submit to intercept fleche-wrapped functions.

Module Contents

fleche.executor.wrap_executor(executor)[source]

Monkey-patch executor.submit to intercept fleche-wrapped functions.

Calling wrap_executor() on an executor that is already wrapped is a no-op: the patch is not stacked, and the original submit continues to refer to the pre-wrap method.

Parameters:

executor – any object with a submit(func, *args, **kwargs) method (e.g. concurrent.futures.Executor subclass instances).

Returns:

The same executor instance, with a replaced submit attribute.