Fix bug in Pool worker dispatch

Description

Pool.run_task and Pool.run_job selected the worker as follows:

  • if worker_id was given, use worker worker_id;
  • else, if the task or job already ran, use its previous worker;
  • else, use worker _tasks_count % size.

Two bugs:

  • Arugment worker_id was tested for truthiness (if worker_id:), so that worker 0 was ignored when requested explicitly: a task or job which had already run on another worker was dispatched there instead.
  • _tasks_count was never incremented: all new tasks and jobs dispatched without worker_id went to worker 0, instead of being distributed among workers.

Batches were not affected, since Pool.run_batch dispatches new jobs on explicit workers, and jobs with worker 0 had no previous worker.

Worker selection is factored into private method __select_worker, which tests worker_id is not None, and increments the dispatch count for each task or job dispatched without explicit or previous worker.

Edited by Étienne Lac

Merge request reports

Loading
Loading