跳转到主要内容

用于构建分布式和可靠并发系统的模块集合

项目描述

https://secure.travis-ci.org/benoitc/flower.png?branch=master

Python中构建分布式和可靠并发系统的模块集合。

要求

  • Python 2.6到3.x版本

  • 支持 libuv <https://github.com/joyent/libuv> 的平台

简单示例

一个简单示例,展示如何创建消费者并使用其他actor功能向其提供数据。

import flower

messages = []
sources = []
def consumer():
    # wait for coming message in the current actor
    while True:
        source, msg = flower.receive()
        if not msg:
            break
        print("got message from %s: %s" % (source.ref, msg))

def publisher1(ref):
    # an actor sending messages to the consumer
    msg = ['hello', 'world']
    for s in msg:
        flower.send(ref, s)

def publisher2(ref):
    msg = ['brave', 'new', 'world', '']
    for s in msg:
        flower.send(ref, s)

ref_consumer = flower.spawn(consumer)
flower.spawn(publisher1, ref_consumer)
flower.spawn(publisher2, ref_consumer)

flower.run()

应该返回

$ python examples/actor_example.py
got message from 1: hello
got message from 2: brave
got message from 1: world
got message from 2: new
got message from 2: world

安装

Flower需要Python 2.6以上版本(是的,Python 3也得到了支持)

要使用pip安装flower,您必须确保已安装了最新的distribute版本

$ curl -O http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py
$ easy_install pip

目前flower只能从源代码安装。要安装或升级到flower的最新发布版本

$ git clone https://github.com/benoitc/flower.git
$ cd flower && pip install -r requirements.txt

许可协议

flower处于公共领域(见UNLICENSE)。flower也可以选择性地在MIT许可协议下提供(见LICENSE),特别适用于不承认公共领域作品的司法管辖区。

项目详情


由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面