Welcome to taskthread’s documentation!

taskthread provides a thread implementation that executes a repetitive task several times without the need to start up a new thread.

Installation

taskthread can be installed with pip, via pip install taskthread.

Usage

TaskThread

class taskthread.TaskThread(task, event=<threading._Event object at 0x1191850>, *args, **kwargs)

A thread object that repeats a task.

Usage example:

from taskthread import TaskThread

import time

def my_task(*args, **kwargs):
    print args, kwargs

task_thread = TaskThread(my_task)
task_thread.start()
for i in xrange(10):
    task_thread.run_task()
    task_thread.join_task()
task_thread.join()
Parameters:
  • task
    A function. This param is the task to execute when
    run_task is called.
  • event
    A threading.Event. This event will be set when run_task
    is called. The default value is a new event, but may be specified for testing purposes.
daemon = True

Threads marked as daemon will be terminated.

join(timeout=None)

Wait for the task to finish

join_task(time_out)

Wait for the currently running task to complete.

Parameters:time_out – An int. The amount of time to wait for the task to finish.
run()

Called by threading.Thread, this runs in the new thread.

run_task(*args, **kwargs)

Run an instance of the task.

Parameters:
  • args – The arguments to pass to the task.
  • kwargs – The keyword arguments to pass to the task.

TaskInProcessException

class taskthread.TaskInProcessException
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.