Cherrypy backgroundtask

I need a simple example call cherrypy.process.plugins.BackgroundTask .

I tried, but I can not get it to work (there are no examples in the documents).

Here is my code:

 def func(): print "blah blah blah" wd = cherrypy.process.plugins.BackgroundTask(15000,func) wd.run() 
+4
source share
1 answer

Short answer: you want to call wd.start() , not wd.run() .

Also, since BackgroundTask is demonic, if you don't do something else to keep the interpreter alive, Python will shut down while your thread is floating in the background, unable to see the result.

This suggests that I always try to make a working example and have not had time yet. This is the code I use that can 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 seems to be an error - the exception handler relies on the self.bus attribute, which does not exist ( bus explicitly specified in other plugins' constructors, but not this class). I don’t think the error is due to my inability to get this to work.

+2
source

All Articles