This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients gvanrossum, vstinner, yselivanov
Date 2015-01-09.15:34:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420817695.78.0.447471935777.issue23208@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2015-01-09 15:34:56vstinnersetrecipients: + vstinner, gvanrossum, yselivanov
2015-01-09 15:34:55vstinnersetmessageid: <1420817695.78.0.447471935777.issue23208@psf.upfronthosting.co.za>
2015-01-09 15:34:55vstinnerlinkissue23208 messages
2015-01-09 15:34:55vstinnercreate