Esempio n. 1
0
def all_handler(parser, args):
    g = Group()
    logical = Logical()
    task = g.spawn(logical.as_dict())
    g.join()
    msg = dump(task.result(),
               explicit_start=True,
               default_flow_style=False,
               humanize=args.humanize)
    parser.exit(0, msg)
Esempio n. 2
0
def match_handler(parser, args):
    g = Group()
    logical = Logical()
    task = g.spawn(logical.match(args.target))
    g.join()
    try:
        resp = task.result()
    except NotFound:
        resp = None
    msg = dump(resp, explicit_start=True, default_flow_style=False)
    parser.exit(0, msg)
Esempio n. 3
0
def read_handler(parser, args):
    g = Group()
    logical = Logical()
    task = g.spawn(logical.read(args.target))
    g.join()
    try:
        resp = task.result()
        code = 0
    except NotFound:
        resp = None
        code = 1
    msg = dump(resp,
               explicit_start=True,
               default_flow_style=False,
               humanize=args.humanize)
    parser.exit(code, msg)
Esempio n. 4
0
    def t():
        while not stopall:
            g = Group()
            for i in range(5):
                g.spawn(f(i))

            g.join()

            time.sleep(random.random() * 0.02)
Esempio n. 5
0
def test_group():
    timespan = 0.1

    @asyncio.coroutine
    def f(i):
        t0 = time.time()
        yield from asyncio.sleep(timespan)
        t = time.time() - t0
        print('finish {}, seconds={:4.2f}'.format(i, t))

    print('testing group')
    t0 = time.time()
    g = Group()
    for i in range(9):
        g.spawn(f(i))
    g.join()
    print('total time: {:4.2f}'.format(time.time() - t0))
    assert timespan < time.time() - t0 < timespan * 1.1
Esempio n. 6
0
    def f2():
        g = Group()
        for c in chars:
            g.spawn(f(c))

        g.join()