PerpetualTimer is just a repeating version of threading._Timer.
What you really want to use is cherrypy.process.plugins.Monitor , which is nothing more than a way to start a separate thread for you. You should use it because it connects to cherrypy.engine, which controls the start and stop behavior for CherryPy servers. If you start your own thread, you will want to stop it when the CP shuts down anyway; the Monitor class already knows how to do this. It uses PerpetualTimer under the hood, to the latest versions, where it has been replaced by the BackgroundTask class.
my_task_runner = Monitor(cherrypy.engine, my_task, frequency=3)
my_task_runner.subscribe()
source
share