from time import sleep
import smokesignal
@smokesignal.on('debug')
def verbose(val):
print "#", val
def main():
for i in range(100):
if i and i%10==0:
smokesignal.emit('debug', i)
sleep(.1)
main()
Here is a newer one: https://github.com/shaunduncan/smokesignal. "smokesignal is a simple python library for sending and receiving signals. It draws some inspiration from the django signal framework but is meant as a general purpose variant." Example:
from time import sleep
import smokesignal
@smokesignal.on('debug')
def verbose(val):
print "#", val
def main():
for i in range(100):
if i and i%10==0:
smokesignal.emit('debug', i)
sleep(.1)
main()
PyDispatcher is used heavily in Django and it's working perfectly for me (and for whole Django community, I guess).
As I remember, there are some performance issues:
Arguments checking made by PyDispatcher is slow.
Unused connections have unnecessary overhead.
AFAIK it's very unlikely you will run into this issues in a small-to-medium sized application. So these issues may not concern you. If you think you need every pound of performance (premature optimization is the root of all evil!), you can look at modifications done to PyDispatcher in Django.
The best dispatch package for python seems to be the dispatch module inside django (called signals in the documentation). It is independent of the rest of django, and is short, documented, tested and very well written.
I recently looked carefully at py-amqplib to act as an AMQP client to a RabbitMQ broker. The latter tool is written in Erlang.
If you're looking to decouple your app. then why couple it to the language itself? Consider using message queues which are language neutral and then you've really got room to grow!
That being said, AMQP takes effort to understand and may be more than you are willing to take on if your app. is working just fine as is. YMMV.
There is also the libraries by PJ Eby, RuleDispatch and the PEAK project, specially Trellis. I don't know what their status actually but the mailing list is quite active.
I have also used the components from the Kamaelia project of the BBC. Axon is an interesting approach, but more component than publisher-consumer inspired. Well, its website is somewhat not up-to-date at all... There was a project or 2 in the Google SoC 2008 and work is being done.
Don't know if it help :)
Edit : I just found Py-notify which is an "unorthodox" implementation of the Observer pattern. It has most of the functionalities that I need for my own tools.
The fact alone that PyPubSub seems to be a somewhat chaotically managed project (the Wiki on SF is dead, the website (another Wiki) which is linked on SF is currently broken) would be enough reason for me not to use it. PyDispatcher has an intact website, but the only documentation they seem to provide is the one for the API generated from the docstrings. No traffic on the mailing list either... a bad sign!
As Mike also mentioned, it's perfectly possible to choose a solution that is independent of Python. Now don't get me wrong, I love Python, but still, in this field it can make sense use a framework that is decoupled from the programming language.
I'm not experienced with messaging, but I'm planning to have a look into a few solutions. So far these two (free, open source) projects seem to be the most promising for me (coincidentally, both are Apache projects):
Both seem to be reasonably matured projects, at least a far as documentation and community. I can't comment on the software's quality though, as I said, I didn't use any of the software.
Qpid ships with client libraries for Python, but you could also use py-amqplib. For ActiveMQ there's pyactivemq, which you can use to connect either via STOMP (Streaming Text Orientated Messaging Protocol) or via Openwire.
发布评论
评论(7)
这是一个较新的:https://github.com/shaunduncan/smokesignal。 “smokesignal 是一个用于发送和接收信号的简单 Python 库。它从 django 信号框架中汲取了一些灵感,但旨在作为通用变体。”示例:
Here is a newer one: https://github.com/shaunduncan/smokesignal. "smokesignal is a simple python library for sending and receiving signals. It draws some inspiration from the django signal framework but is meant as a general purpose variant." Example:
PyDispatcher 在 Django 它非常适合我(我猜也适合整个 Django 社区)。
我记得,存在一些性能问题:
据我所知,您不太可能在中小型应用程序中遇到此问题。 所以这些问题可能与您无关。 如果您认为需要每一磅性能(过早的优化是万恶之源!),您可以查看 Django 中对 PyDispatcher 所做的修改。
希望这可以帮助。
PyDispatcher is used heavily in Django and it's working perfectly for me (and for whole Django community, I guess).
As I remember, there are some performance issues:
AFAIK it's very unlikely you will run into this issues in a small-to-medium sized application. So these issues may not concern you. If you think you need every pound of performance (premature optimization is the root of all evil!), you can look at modifications done to PyDispatcher in Django.
Hope this helps.
python最好的调度包似乎是里面的 调度模块 django(在文档中称为 信号)。 它独立于 django 的其余部分,并且简短、有文档、经过测试并且编写得很好。
编辑:我将此项目分叉为Python的独立信号项目。
The best dispatch package for python seems to be the dispatch module inside django (called signals in the documentation). It is independent of the rest of django, and is short, documented, tested and very well written.
Edit: I forked this project into an independent signal project for Python.
我最近仔细研究了 py-amqplib 作为 RabbitMQ 代理的 AMQP 客户端。 后一个工具是用 Erlang 编写的。
如果您希望解耦您的应用程序。 那么为什么要把它与语言本身结合起来呢? 考虑使用语言中立的消息队列,然后你就真的有成长的空间了!
话虽这么说,AMQP 需要付出努力才能理解,并且可能超出您在应用程序中愿意承担的程度。 工作得很好。 YMMV。
I recently looked carefully at py-amqplib to act as an AMQP client to a RabbitMQ broker. The latter tool is written in Erlang.
If you're looking to decouple your app. then why couple it to the language itself? Consider using message queues which are language neutral and then you've really got room to grow!
That being said, AMQP takes effort to understand and may be more than you are willing to take on if your app. is working just fine as is. YMMV.
还有 PJ Eby、RuleDispatch 和 PEAK 项目的库,特别是 Trellis。 我不知道他们的实际状态,但邮件列表非常活跃。
PyPi 上 Trellis 的最新版本
Trellis doc
我还使用了 BBC 的 Kamaelia 项目。 Axon 是一种有趣的方法,但更多的是受发布者-消费者启发的组件。 嗯,它的网站有点不是最新的...Google SoC 2008 中有一个或两个项目,工作正在进行中。
不知道是否有帮助:)
编辑:我刚刚发现 Py-notify 这是观察者模式的“非正统”实现。 它具有我自己的工具所需的大部分功能。
There is also the libraries by PJ Eby, RuleDispatch and the PEAK project, specially Trellis. I don't know what their status actually but the mailing list is quite active.
Last version of Trellis on PyPi
Trellis doc
I have also used the components from the Kamaelia project of the BBC. Axon is an interesting approach, but more component than publisher-consumer inspired. Well, its website is somewhat not up-to-date at all... There was a project or 2 in the Google SoC 2008 and work is being done.
Don't know if it help :)
Edit : I just found Py-notify which is an "unorthodox" implementation of the Observer pattern. It has most of the functionalities that I need for my own tools.
我发现一些尚未提及的库:
Some libraries I have found that haven't yet been mentioned:
仅 PyPubSub 似乎是一个管理有点混乱的项目(SF 上的 Wiki 已死,SF 上链接的网站(另一个 Wiki)目前已损坏)这一事实就足以让我不使用它。
PyDispatcher 有一个完整的网站,但他们提供的唯一文档似乎是从文档字符串生成的 API 的文档。 邮件列表上也没有流量...这是一个坏兆头!
正如 Mike 还提到的,完全有可能选择一个独立于 Python 的解决方案。 现在请不要误解我的意思,我喜欢 Python,但是在这个领域,使用与编程语言分离的框架仍然是有意义的。
我对消息传递没有经验,但我计划研究一些解决方案。 到目前为止,这两个(免费、开源)项目对我来说似乎是最有前途的(巧合的是,这两个项目都是 Apache 项目):
两者似乎都是相当成熟的项目,至少就文档和社区而言。 不过,我无法评论该软件的质量,正如我所说,我没有使用任何软件。
Qpid 附带了 Python 客户端库,但您也可以使用 py-amqplib。 对于 ActiveMQ,有 pyactivemq,您可以使用它通过 STOMP(面向流文本的消息传递)进行连接协议)或通过 Openwire。
The fact alone that PyPubSub seems to be a somewhat chaotically managed project (the Wiki on SF is dead, the website (another Wiki) which is linked on SF is currently broken) would be enough reason for me not to use it.
PyDispatcher has an intact website, but the only documentation they seem to provide is the one for the API generated from the docstrings. No traffic on the mailing list either... a bad sign!
As Mike also mentioned, it's perfectly possible to choose a solution that is independent of Python. Now don't get me wrong, I love Python, but still, in this field it can make sense use a framework that is decoupled from the programming language.
I'm not experienced with messaging, but I'm planning to have a look into a few solutions. So far these two (free, open source) projects seem to be the most promising for me (coincidentally, both are Apache projects):
Both seem to be reasonably matured projects, at least a far as documentation and community. I can't comment on the software's quality though, as I said, I didn't use any of the software.
Qpid ships with client libraries for Python, but you could also use py-amqplib. For ActiveMQ there's pyactivemq, which you can use to connect either via STOMP (Streaming Text Orientated Messaging Protocol) or via Openwire.