Exemple #1
0
# 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()
def scheduler_run(tasklet_func):
    t = flower.tasklet(tasklet_func)()
    while t.alive:
        flower.run()
Exemple #3
0
def main():
    tasklet(say)("world")
    say("hello")

    run()
Exemple #4
0
import threading
from flower import schedule, run, getruncount, schedule, tasklet

try:
    from thread import get_ident
except ImportError:  #python 3
    from _thread import get_ident


def secondary_thread_func():
    runcount = getruncount()
    print("THREAD(2): Has", runcount, "tasklets in its scheduler")


def main_thread_func():
    print("THREAD(1): Waiting for death of THREAD(2)")
    while thread.is_alive():
        schedule()
    print("THREAD(1): Death of THREAD(2) detected")


mainThreadTasklet = tasklet(main_thread_func)()

thread = threading.Thread(target=secondary_thread_func)
thread.start()

print("we are in %s" % get_ident())
run()
import threading
from flower import schedule, run, getruncount, schedule, tasklet

try:
    from thread import get_ident
except ImportError: #python 3
    from _thread import get_ident

def secondary_thread_func():
    runcount = getruncount()
    print("THREAD(2): Has", runcount, "tasklets in its scheduler")

def main_thread_func():
    print("THREAD(1): Waiting for death of THREAD(2)")
    while thread.is_alive():
        schedule()
    print("THREAD(1): Death of THREAD(2) detected")

mainThreadTasklet = tasklet(main_thread_func)()

thread = threading.Thread(target=secondary_thread_func)
thread.start()

print("we are in %s" % get_ident())
run()
Exemple #6
0
def main():
    tasklet(say)("world")
    say("hello")

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