Ejemplo n.º 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()
Ejemplo n.º 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()
def scheduler_run(tasklet_func):
    t = flower.tasklet(tasklet_func)()
    while t.alive:
        flower.run()
Ejemplo n.º 4
0
def main():
    tasklet(say)("world")
    say("hello")

    run()
Ejemplo n.º 5
0
def main():
    tasklet(say)("world")
    say("hello")

    run()
def scheduler_run(tasklet_func):
    t = flower.tasklet(tasklet_func)()
    while t.alive:
        flower.run()