Search code examples
pythonpython-3.xpyramidcherrypy

What is the proper way to handle periodic housekeeping tasks in Python/Pyramid/CherryPy?


I have a python web-app that uses Pyramid/CherryPy for the webserver.

It has a few periodic housekeeping tasks that need to be run - Clearing out stale sessions, freeing their resources, etc...

What is the proper way to manage this? I can fairly easily just run a additional "housekeeping" thread (and use a separate scheduler, like APscheduler), but having a separate thread reach into the running server thread(s) just seems like a really clumsy solution. CherryPy is already running the server in a (multi-threaded) eventloop, it seems like it should be possible to somehow schedule periodic events through that.


Solution

  • Have a look at the "main" channel at http://cherrypy.readthedocs.org/en/latest/progguide/extending/customplugins.html