Tasks

TaskQueue A task queue, consisting of a queue and a number of workers.
Task A task object represents some unit of work to be done.
TaskWorker A worker thread that runs tasks from a TaskQueue.
TaskQueue.get Get a task from the task queue.
TaskQueue.put Add a task to the task queue, and spawn a worker if we’re not full.
Task.is_alive Return true if this task hasn’t been finished.
Task.join Wait for this task to finish.
TaskWorker.run Repeatedly get tasks from the TaskQueue and execute them.
class TaskQueue(threads=48, delay=0)[source]

Bases: object

A task queue, consisting of a queue and a number of workers.

Parameters:
  • threads (integer) – Number of threads to create (if needed).
  • delay – Time to wait between
get()[source]

Get a task from the task queue. Mainly used by workers.

Returns:A Task object that hasn’t been executed yet.
Return type:Task
Raises IndexError:
 If there are no tasks in the queue.
put(method, *args)[source]

Add a task to the task queue, and spawn a worker if we’re not full.

Parameters:
  • method (string) – Named method to run.
  • args (list) – Arguments to pass to the named method to run.
Returns:

A Task that will be executed by a worker at a later time.

Return type:

Task

class Task(method, *args)[source]

Bases: object

A task object represents some unit of work to be done.

Parameters:
  • method (function) – The actual method (function) to execute.
  • args (list) – Arguments to pass to the named method to run.
is_alive()[source]

Return true if this task hasn’t been finished.

Returns:Whether or not the task is still alive.
Return type:boolean
join()[source]

Wait for this task to finish.

class TaskWorker(task_queue, delay=0)[source]

Bases: threading.Thread

A worker thread that runs tasks from a TaskQueue.

Parameters:
  • task_queue (TaskQueue) – Task queue to get tasks from.
  • delay – Time to wait in-between execution.
run()[source]

Repeatedly get tasks from the TaskQueue and execute them.

Previous topic

Fabric

Next topic

CRC32