summaryrefslogtreecommitdiff
path: root/examples/stacks.py
blob: 0b7e0b2c325dc037dcae6739a1931beb70dc5edf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Crude demo for print_stack()."""


from asyncio import *


@coroutine
def helper(r):
    print('--- helper ---')
    for t in Task.all_tasks():
        t.print_stack()
    print('--- end helper ---')
    line = yield from r.readline()
    1/0
    return line

def doit():
    l = get_event_loop()
    lr = l.run_until_complete
    r, w = lr(open_connection('python.org', 80))
    t1 = async(helper(r))
    for t in Task.all_tasks(): t.print_stack()
    print('---')
    l._run_once()
    for t in Task.all_tasks(): t.print_stack()
    print('---')
    w.write(b'GET /\r\n')
    w.write_eof()
    try:
        lr(t1)
    except Exception as e:
        print('catching', e)
    finally:
        for t in Task.all_tasks():
            t.print_stack()
    l.close()


def main():
    doit()


if __name__ == '__main__':
    main()