buildgrid.server.threading module
- class buildgrid.server.threading.ContextThreadPoolExecutor(max_workers: int | None = None, thread_name_prefix: str = '', initializer: Callable[[], Any] | None = None, initargs: tuple[Any, ...] = (), immediate_copy: bool = False)
Bases:
ThreadPoolExecutor- submit(fn: ~collections.abc.Callable[[~_P], ~buildgrid.server.threading._T], /, *args: ~typing.~_P, **kwargs: ~typing.~_P) Future[_T]
Submits a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(*args, **kwargs) and returns a Future instance representing the execution of the callable.
- Returns:
A Future representing the given call.
- class buildgrid.server.threading.ContextThread(target: Callable[[_P], _T], name: str | None = None, args: Iterable[Any] = (), kwargs: dict[str, Any] | None = None, *, daemon: bool | None = None)
Bases:
Thread
- class buildgrid.server.threading.ContextWorker(target: Callable[[Event], None], name: str | None = None, *, on_shutdown_requested: Callable[[], None] | None = None)
Bases:
object- is_alive() bool
- start() None
- stop() None
- wait(timeout: float | None = None) None
- buildgrid.server.threading.run_concurrently(fn: Callable[[T], R], items: Sequence, executor: Executor | None, max_helpers: int | None = None) list[R]
Apply
fnto every item and return the results in input order.The calling thread always processes items itself. Up to
max_helpers(defaultlen(items) - 1) helper tasks are submitted toexecutorand process items too if a worker picks them up before the work runs out; helpers that haven’t started by then are cancelled. A saturated (or absent) executor therefore degrades to running everything sequentially on the calling thread, never to waiting in a queue.Each call to
fnruns in its own copy of the caller’s context, wherever it runs, so context variables set byfndon’t leak into the caller or other items.If any call raises, no further items are started, in-flight calls are awaited, and the exception from the lowest-index failing item is re-raised, as
Executor.mapwould. Items are started in input order, so every item before a failing one has also run.