taskthread

raw JSON →
1.4 verified Fri May 01 auth: no python

A lightweight Python module for running a repetitive task on a single dedicated thread. Currently at version 1.4, with infrequent releases.

pip install taskthread
error AttributeError: module 'taskthread' has no attribute 'TaskThread'
cause Incorrect import statement (e.g., 'import taskthread' then 'taskthread.TaskThread').
fix
Use 'from taskthread import TaskThread'.
error TypeError: 'float' object is not callable
cause Passed a float as the first argument instead of a callable.
fix
Ensure first argument is a function or callable object.
gotcha The interval parameter is in seconds (float), not milliseconds. Passing a value like 1000 will cause a long delay.
fix Ensure interval is in seconds (e.g., 0.5 for 500ms).
gotcha TaskThread uses a simple while loop with sleep; if the task takes longer than the interval, they will overlap because no lock is used.
fix Design tasks to complete quickly or add your own synchronization.

Create a TaskThread that executes my_task every 2 seconds, start it, then stop after 10 seconds.

from taskthread import TaskThread
import time

def my_task():
    print("Task execution at", time.time())

# Run my_task every 2 seconds
t = TaskThread(my_task, 2)
t.start()
time.sleep(10)  # Let it run for a while
t.stop()