如何在CherryPy的异步执行后处理? [英] How to execute asynchronous post-processing in CherryPy?

查看:177
本文介绍了如何在CherryPy的异步执行后处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:
试想一下,你有一个标准的CherryPy招呼字应用:

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

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

和你想要做一些后期处理,即记录请求处理或只需登录一个事实,即我们从特定IP调用。你会做什么可能是:

and you would like to do some post-processing, i.e. record request processing or just log the fact that we were called from specific IP. What you would do is probably:

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

不过,这将添加到您的请求处理时间。 (顺便说一句,而且很可能你会用装饰,甚至一些更复杂的方法,如果你想叫它每个功能)。

However, that will add to your request processing time. (btw. And probably you will use decorators, or even some more sophisticated method if you would like to call it on every function).

问:
有没有建立一个全球性的线程队列知道(缓冲)到每个请求可以写邮件(事件)需要被记录的方式,而一些神奇的功能会抓住它和后处理?你知道一种模式,这样的事?

Question: Is there a way of creating a global threading aware queue (buffer) to which each request can write messages (events) that needs be logged, while some magic function will grab it and post-process? Would you know a pattern for such a thing?

我敢打赌,CherryPy的支持类似的东西: - )

I bet that CherryPy supports something like that :-)

感谢您提前...

推荐答案

环球线程队列意识到被称为Queue.Queue。我只是说这个配方在 http://tool​​s.cherrypy.org/wiki/BackgroundTaskQueue

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

这篇关于如何在CherryPy的异步执行后处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆