I need a simple example of invoking the cherrypy.process.plugins.BackgroundTask.
I tried it out but can’t seem to get it to work (no examples in the docs).
Here is my code:
def func():
print "blah blah blah"
wd = cherrypy.process.plugins.BackgroundTask(15000,func)
wd.run()
The short answer is, you want to call
wd.start(), notwd.run().Also, because
BackgroundTaskis daemonic, unless you are doing something else to keep the interpreter alive, Python will exit while your thread floats in the background with no way to see the output.That said, I’ve been futzing around with trying to make a working example and haven’t succeeded yet. This is the code I am using, which may suck:
Finally, looking at the source of
BackgroundTask, I see what appears to be a bug — the exception handler relies on aself.busattribute that doesn’t exist (busis explicitly set in the other plugins’ constructors, but not this class). I don’t think that bug is related to my failure to get this working.