How to use the flower.core.tasklet function in flower

To help you get started, we’ve selected a few flower examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benoitc / flower / test / test_scheduler.py View on Github external
def f():
            rlist.append('f')
            return 1/0

        def g():
            rlist.append('bg')
            core.schedule()
            rlist.append('ag')

        def h():
            rlist.append('bh')
            core.schedule()
            rlist.append('ah')

        tg = core.tasklet(g)()
        tf = core.tasklet(f)()
        th = core.tasklet(h)()

        try:
            core.run()
        except ZeroDivisionError:
            rlist.append('E')
        core.schedule()
        core.schedule()

        assert rlist == "bg f E bh ag ah".split()
github benoitc / flower / test / test_scheduler.py View on Github external
def test_autocatch_taskletexit(self):
        # Tests if TaskletExit is caught correctly in core.tasklet.setup().
        def f():
            core.schedule()

        t = core.tasklet(f)()
        t.run()
        t.kill()
github benoitc / flower / test / test_scheduler.py View on Github external
rlist.append('f')
            return 1/0

        def g():
            rlist.append('bg')
            core.schedule()
            rlist.append('ag')

        def h():
            rlist.append('bh')
            core.schedule()
            rlist.append('ah')

        tg = core.tasklet(g)()
        tf = core.tasklet(f)()
        th = core.tasklet(h)()

        try:
            core.run()
            # cheating, can't test for ZeroDivisionError
        except ZeroDivisionError:
            rlist.append('E')
        core.schedule()
        core.schedule()

        assert rlist == "bg f E bh ag ah".split()
github benoitc / flower / test / test_scheduler.py View on Github external
def main():
            rlist.append('m')
            cg = core.tasklet(g)()
            cf = core.tasklet(f)()
            core.run()
            rlist.append('m')
github benoitc / flower / test / test_scheduler.py View on Github external
def test_getruncount(self):
        assert core.getruncount() == 1
        def with_schedule():
            assert core.getruncount() == 2

        t1 = core.tasklet(with_schedule)()
        assert core.getruncount() == 2
        core.schedule()
        def with_run():
            assert core.getruncount() == 1

        t2 = core.tasklet(with_run)()
        core.run()
github benoitc / flower / test / test_channel.py View on Github external
def test_simple_channel(self):
        output = []
        def print_(*args):
            output.append(args)

        def Sending(channel):
            print_("sending")
            channel.send("foo")

        def Receiving(channel):
            print_("receiving")
            print_(channel.receive())

        ch=core.channel()

        task=core.tasklet(Sending)(ch)

        # Note: the argument, schedule is taking is the value,
        # schedule returns, not the task that runs next

        #core.schedule(task)
        core.schedule()
        task2=core.tasklet(Receiving)(ch)
        #core.schedule(task2)
        core.schedule()

        core.run()

        assert output == [('sending',), ('receiving',), ('foo',)]
github benoitc / flower / test / test_time.py View on Github external
def test_sleep2(self):
        rlist = []

        def f():
            sleep()
            rlist.append('a')

        def f1():
            rlist.append('b')

        core.tasklet(f)()
        core.tasklet(f1)()
        core.run()

        assert rlist == ['b', 'a']
github benoitc / flower / test / test_channel.py View on Github external
def test_send_counter(self):
        import random

        numbers = list(range(20))
        random.shuffle(numbers)

        def counter(n, ch):
            for i in xrange(n):
                core.schedule()
            ch.send(n)

        ch = core.channel()
        for each in numbers:
            core.tasklet(counter)(each, ch)

        core.run()

        rlist = []
        while ch.balance:
            rlist.append(ch.receive())

        numbers.sort()
        assert rlist == numbers
github benoitc / flower / test / test_channel.py View on Github external
def test_send_exception(self):
        def exp_sender(chan):
            chan.send_exception(Exception, 'test')

        def exp_recv(chan):
            try:
                val = chan.receive()
            except Exception as exp:
                assert exp.__class__ is Exception
                assert str(exp) == 'test'

        chan = core.channel()
        t1 = core.tasklet(exp_recv)(chan)
        t2 = core.tasklet(exp_sender)(chan)
        core.run()
github benoitc / flower / flower / time.py View on Github external
def _func(now, handle):
        core.tasklet(f)(*args, **kwargs)
        core.schedule()