{"id":9358,"library":"tgscheduler","title":"TGScheduler","description":"TGScheduler is a pure Python scheduler library, currently at version 1.7.0. It enables applications to run one-time or recurring tasks, supporting execution in-process (using threads), as forked processes, or synchronously within the main code. The library is based on the scheduler originally built into TurboGears 1, offering a straightforward approach to task automation. Its release cadence is infrequent, with the last update in 2015.","status":"maintenance","version":"1.7.0","language":"en","source_language":"en","source_url":"https://pypi.org/project/tgscheduler/","tags":["scheduler","task-scheduling","pure-python","utility"],"install":[{"cmd":"pip install tgscheduler","lang":"bash","label":"Install TGScheduler"}],"dependencies":[],"imports":[{"note":"The primary Scheduler class is directly available under the top-level package.","wrong":"from tgscheduler.scheduler import Scheduler","symbol":"Scheduler","correct":"from tgscheduler import Scheduler"}],"quickstart":{"code":"from tgscheduler import Scheduler\nimport time\nimport logging\n\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n\ndef my_task(message):\n    logging.info(f\"Executing task with message: {message}\")\n\ns = Scheduler()\n\n# Schedule a task to run once, 5 seconds from now\ns.add_task(my_task, args=('One-time task!',), delay=5)\n\n# Schedule a recurring task every 10 seconds\ns.add_task(my_task, args=('Recurring task!',), interval=10, initialdelay=2, name='RecurringExample')\n\nlogging.info(\"Scheduler started. Tasks will run.\")\ntry:\n    # Run the scheduler in a blocking loop (or integrate into an existing event loop)\n    while True:\n        s.tick()\n        time.sleep(1) # Sleep to prevent busy-waiting\nexcept KeyboardInterrupt:\n    logging.info(\"Scheduler stopped by user.\")\n    s.shutdown()","lang":"python","description":"This quickstart demonstrates how to initialize the TGScheduler, add both one-time and recurring tasks, and run the scheduler in a simple blocking loop. Tasks are defined as callable functions, and arguments can be passed via the `args` parameter. The `delay` argument schedules a task for a single future execution, while `interval` schedules it for recurring executions. Logging is included to show task execution."},"warnings":[{"fix":"Run `s.tick()` in a separate thread or use an asynchronous loop that yields control, calling `s.tick()` at appropriate intervals.","message":"TGScheduler is a blocking scheduler if `tick()` is called in a tight loop. To integrate it into existing asynchronous applications (e.g., web servers), ensure `tick()` is called periodically without blocking the main event loop, or run the scheduler in a separate thread.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For new projects or those requiring active development/support, evaluate modern alternatives like APScheduler or schedule. If using TGScheduler, thoroughly test on your target Python version.","message":"The project appears to be in maintenance mode, with the last PyPI release in 2015. While functional, it might not receive updates for new Python versions or critical bug fixes. Consider more actively maintained alternatives for new projects requiring robust scheduling.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Always provide `args` as a tuple, e.g., `s.add_task(my_func, args=('arg1', 'arg2',))` or `s.add_task(my_func, args=('single_arg',))`.","message":"TGScheduler's `add_task` method requires careful handling of task arguments. If a task function takes arguments, they must be passed as a tuple to the `args` parameter, even for a single argument.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `args` is a tuple containing all required positional arguments for `my_task`. Example: `s.add_task(my_task, args=('Hello',))`.","cause":"Attempting to schedule a function that expects arguments without providing them correctly via the `args` parameter.","error":"TypeError: my_task() missing 1 required positional argument: 'message'"},{"fix":"The Scheduler class is directly available from the top-level `tgscheduler` package. Use `from tgscheduler import Scheduler`.","cause":"Incorrect import path for the Scheduler class.","error":"ModuleNotFoundError: No module named 'tgscheduler.scheduler'"},{"fix":"Run the scheduler's `tick()` method in a separate thread using `threading.Thread` or integrate it carefully into the application's event loop to ensure it's periodically called without blocking.","cause":"TGScheduler's `tick()` method needs to be called regularly. If the main thread is blocked (e.g., by a web server's run loop or a GUI event loop), `tick()` won't be executed.","error":"Task does not run or runs inconsistently in a web framework/GUI application."}]}