Giter Club home page Giter Club logo

flower-3's Introduction


DEPPRECATED Flower is now superseded by Offset .


Flower

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

collection of modules to build distributed and reliable concurrent systems in Python.

a = โ€œโ€

def f():
   print(a)

def hello():
    a = "hello, world"
    tasklet(f)()

Requirements

Simple example

A simple example showing how to create a simple echo server.

# Echo server program
from flower import tasklet, run
from flower.net import Listen


# handle the connection. It return data to the sender.
def handle_connection(conn):
    while True:
        data = conn.read()
        if not data:
            break

        conn.write(data)


# Listen on tcp port 8000 on localhost
l = Listen(('127.0.0.1', 8000), "tcp")
try:
    while True:
        try:

            # wait for new connections (it doesn't block other tasks)
            conn, err = l.accept()

            # Handle the connection in a new task.
            # The loop then returns to accepting, so that
            # multiple connections may be served concurrently.

            t = tasklet(handle_connection)(conn)
        except KeyboardInterrupt:
            break
finally:
    l.close()

run()

And the echo client:

from flower import tasklet, run, schedule
from flower.net import Dial


# connect to the remote server
conn = Dial("tcp", ('127.0.0.1', 8000))

# start to handle the connection
# we send a string to the server and fetch the
# response back

for i in range(3):
    msg = "hello"
    print("sent %s" % msg)
    resp = conn.write(msg)
    ret = conn.read()
    print("echo: %s" % ret)

conn.close()
run()

Installation

Flower requires Python superior to 2.6 (yes Python 3 is supported)

To install flower using pip you must make sure you have a recent version of distribute installed:

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

For now flower can only be installed from sources. To install or upgrade to the latest released version of flower:

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

License

flower is available in the public domain (see UNLICENSE). flower is also optionally available under the MIT License (see LICENSE), meant especially for jurisdictions that do not recognize public domain works.

flower-3's People

Contributors

benoitc avatar ronnypfannschmidt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.