The short answer is, you want to call wd.start()
, not wd.run()
.
Also, because BackgroundTask
is 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:
import cherrypy.process.plugins
def func():
print "blah blah blah"
wd = cherrypy.process.plugins.BackgroundTask(15, func)
wd.start()
raw_input() # hit return when you are bored
wd.cancel()
Finally, looking at the source of BackgroundTask
, I see what appears to be a bug -- the exception handler relies on a self.bus
attribute that doesn't exist (bus
is 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.