コード例 #1
0
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()
コード例 #2
0
from flower import spawn, receive, send, run

messages = []
sources = []
def consumer():
    # wait for coming message in the current actor
    while True:
        source, msg = 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:
        send(ref, s)

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

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

run()
コード例 #3
0
def scheduler_run(tasklet_func):
    t = flower.tasklet(tasklet_func)()
    while t.alive:
        flower.run()
コード例 #4
0
ファイル: hello.py プロジェクト: benoitc/flower
def main():
    tasklet(say)("world")
    say("hello")

    run()
コード例 #5
0
ファイル: hello.py プロジェクト: BigRLab/flower
def main():
    tasklet(say)("world")
    say("hello")

    run()
コード例 #6
0
def scheduler_run(tasklet_func):
    t = flower.tasklet(tasklet_func)()
    while t.alive:
        flower.run()