How to execute asynchronous post-processing in CherryPy?

前端 未结 3 1841
你的背包
你的背包 2021-02-09 23:48

Context: Imagine that you have a standard CherryPy hello word app:

   def index(self):
      return \"Hello world!\"
   index.exposed = True


        
相关标签:
3条回答
  • 2021-02-09 23:59

    The "global threading aware queue" is called Queue.Queue. I just added a recipe for this at http://tools.cherrypy.org/wiki/BackgroundTaskQueue

    0 讨论(0)
  • 2021-02-10 00:10

    As i was looking for this and it's now outdated, i found it useful to provide the correct (2012ish) answer. Simply add this at the beginning of the function that handles your url :

    cherrypy.request.hooks.attach('on_end_request', mycallbackfunction)
    

    There's more infos on hooks in the documentation but it's not very clear to me.

    0 讨论(0)
  • 2021-02-10 00:12

    An on_end_request custom tool may be what you want.

    0 讨论(0)
提交回复
热议问题