New submission from STINNER Victor:

One pain point of asynchronous programming is to understand bugs and rebuild 
the chain of callbacks / coroutines / tasks. I added the source traceback to 
Handle, Future (Task) and CoroWrapper to help debugging.

Here is a new enhancement to provide more context in debug mode: add 
BaseEventLoop._current_handle which is the handle currently executed.

The first usage is the call_exception_handler() which logs the source traceback 
of the current handle in debug mode.

Example:
---
import asyncio

def bug():
    loop.call_exception_handler({'message': 'bug!'})

def schedule_bug():
    bug()

loop = asyncio.get_event_loop()
loop.call_soon(schedule_bug)
loop.call_later(1, loop.stop)
loop.run_forever()
loop.close()
---

Output in debug mode, without the patch:
---
bug!
---

Output in debug mode, with the patch:
---
bug!
handle_traceback: Handle created at (most recent call last):
  File "x.py", line 10, in <module>
    loop.call_soon(schedule_bug)
---

Later, I plan to use the source traceback of the current handle in more places. 
For example, use it to log messages.

I would like to know "who" logged the "SSL handshake failed". At the beginning, 
I wanted to add a source traceback to all transports, but it looks simpler to 
get the source traceback of the current handler. Moreover, this traceback is 
more useful than the source traceback of the transport.

Previous try to add the source traceback to transports:
https://code.google.com/p/tulip/issues/detail?id=212

----------
components: asyncio
files: current_handle.patch
keywords: patch
messages: 233759
nosy: gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio: add BaseEventLoop._current_handle
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file37655/current_handle.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23208>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to