Files
deb-python-trollius/examples/stacks.py
Victor Stinner 684f3be000 Python issue #23208: Add BaseEventLoop._current_handle
In debug mode, BaseEventLoop._run_once() now sets the
BaseEventLoop._current_handle attribute to the handle currently executed.
In release mode or when no handle is executed, the attribute is None.

BaseEventLoop.default_exception_handler() displays the traceback of the current
handle if available.
2015-01-26 10:52:45 +01:00

45 lines
830 B
Python

"""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()