Timeloop
raw JSON → 1.0.2 verified Sat May 09 auth: no python maintenance
A simple library for scheduling periodic tasks using decorators. Current version: 1.0.2. Low release cadence; last update in 2021.
pip install timeloop Common errors
error AttributeError: module 'timeloop' has no attribute 'Timeloop' ↓
cause Importing incorrectly (e.g., `import timeloop` then `timeloop.Timeloop` works, but `from timeloop import timeloop` is wrong).
fix
Use
from timeloop import Timeloop. error TypeError: 'Timeloop' object is not callable ↓
cause Attempting to call the Timeloop class as a function (e.g., `tl = Timeloop()` is correct; `tl = Timeloop` missing parentheses is wrong).
fix
Instantiate with
tl = Timeloop(). Warnings
gotcha Using tl.start(block=True) will block the main thread. If used in a script without a background thread, the program will hang until interrupted. ↓
fix Use tl.start(block=False) and keep the main thread alive manually, or run in a separate thread.
deprecated The library has not been updated since 2021; it uses the deprecated `utcnow()` internally and may break in future Python versions (Python 3.12 deprecated `datetime.utcnow()`). ↓
fix Consider alternatives like `schedule`, `apscheduler`, or use a fork with fixes.
gotcha The `@tl.job` decorator does not capture exceptions; if a job raises an exception, the scheduler stops without warning. ↓
fix Wrap job body in try/except or use a custom error handler via `tl._handle_exception`.
Imports
- Timeloop
from timeloop import Timeloop
Quickstart
from timeloop import Timeloop
from datetime import timedelta
tl = Timeloop()
@tl.job(interval=timedelta(seconds=5))
def job1():
print("5 seconds job")
if __name__ == '__main__':
tl.start(block=True)