parallel

Classes

class behave_priority.parallel.ParallelCoordinator(coord_dir, worker_id=None)[source]

Bases: object

File-based coordination for parallel workers.

Each worker creates and maintains its own JSON file in a shared coordination directory. The file contains the worker’s failure count and critical-failure flag. Global state is computed by reading all worker files in the directory.

Variables:
  • coord_dir – Directory where worker files are stored.

  • worker_id – Unique identifier for this worker (defaults to PID).

cleanup()[source]

Remove this worker’s file from the coordination directory.

Return type:

None

report_failure(*, is_critical=False)[source]

Record a failure for this worker.

Atomically updates the worker’s file with the new failure count.

Parameters:

is_critical (bool) – Whether the failure was in a critical scenario.

Return type:

None

should_stop(stop_after_failures, stop_on_critical)[source]

Check if global fail-fast conditions have been met.

Reads all worker files in the coordination directory and aggregates failure counts and critical-failure flags. Files that fail to parse, or that were created before this run (stale files left by a crashed previous run), are ignored.

Parameters:
  • stop_after_failures (int | None) – Global failure threshold, or None.

  • stop_on_critical (bool) – Whether to stop on any critical failure.

Return type:

bool

Returns:

True if global conditions indicate execution should stop.

Functions

behave_priority.parallel.get_coord_dir()[source]

Get the coordination directory from the environment variable.

Return type:

str | None

Returns:

The path from BEHAVE_PRIORITY_COORD_DIR env var, or None.

behave_priority.parallel.create_coordinator(worker_id=None)[source]

Create a ParallelCoordinator from the env var, if set.

Parameters:

worker_id (str | None) – Optional worker identifier. Defaults to PID.

Return type:

ParallelCoordinator | None

Returns:

A ParallelCoordinator if BEHAVE_PRIORITY_COORD_DIR is set, otherwise None.

behave_priority.parallel.cleanup_coordinator(context)[source]

Clean up the parallel coordinator for this worker.

Intended for use in after_all. Removes the worker’s file from the coordination directory.

Parameters:

context (object) – Behave’s context object.

Return type:

None