Skip to main content

Abandoned calls and worker replacement

Why calls are abandoned​

Python cannot stop a thread from outside. A sync task that is blocked, for example on a device that does not answer, runs until the blocking call returns.

The driver cannot wait that long: the host passed its deadline, or the run was cancelled. The driver therefore stops waiting and tells the worker to abandon the call. The task's thread continues on the worker, and its result is discarded.

Async tasks do not need this. An async task stops at the call it is awaiting, and its session is kept.

Two timings on the driver​

NameValueMeaning
Poll interval0.2 secondsHow often a sync relay stops waiting for the worker to check for a deadline or a cancellation
Cancel grace5 secondsHow long a cancelled relay waits for the worker's final result before it abandons the call

These values are not runner options.

What happens after a deadline (sync task)​

What happens after a cancellation (sync task)​

  1. The relay sends cancel to the worker. The task stops at its next checkpoint.
  2. The relay waits up to 5 seconds for the worker's final result. That result holds the results of the subtasks completed before the cancellation.
  3. When no final result arrives in time, the relay sends abandon. The host is recorded as cancelled, and the worker treats the call as after a deadline.

Spare threads keep the capacity​

A worker has hosts_per_worker + max_abandoned_calls threads for sync tasks and admits hosts_per_worker calls at the same time. Up to max_abandoned_calls abandoned calls, 4 by default, can therefore still be running without reducing the number of hosts the worker runs.

When a worker is replaced​

At the start of each run, the pool asks each idle worker for its status. When a worker has more than max_abandoned_calls abandoned calls still running, the pool retires it: it stops the worker and starts a new one in the same place.

  • A worker that a run in progress in the same process uses is retired at a later run.
  • A worker that does not answer the status call in time is kept.
  • The hosts of a retired worker open new sessions at their next run.

A simpler rule would replace a worker at the first deadline. That rule would close the sessions of every other host on the worker each time one device is slow, so it is not used.