Issue 23587: asyncio: use the new traceback.TracebackException class (original) (raw)
Issue23587
Created on 2015-03-05 02:33 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (4) | ||
---|---|---|
msg237234 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2015-03-05 02:33 |
In Python 3, an exception contains a traceback. A traceback contains frames which contain local variables. Sometimes, the newly raised exception is a local variable and so we get a reference cycle: exc -> traceback -> frame -> exc... In asyncio, it's a real issue because exception objects are kept alive longer than an except block. They are stored in Future objects by Future.set_exception() (and so Task.set_exception()). Python 3.5 has a new traceback.TracebackException (see issue #17911) which creates a light "view" which can be used to format a traceback and the view doesn't contain local variables. It would be great if we can use it. The problem is to that Future.result() raises the exception set in Future.set_exception(), and we except to get the traceback of the exception. So it's unclear to me how long we must store the exception. Maybe we can only store a traceback.TracebackException in release mode and store the full traceback object in debug mode? Such change means that enabling the debug mode may create reference cycles (compared to the new release mode), which can be very suprising and annoying. | ||
msg237235 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2015-03-05 02:34 |
See also: https://code.google.com/p/tulip/issues/detail?id=155 https://code.google.com/p/tulip/issues/detail?id=42 http://bugs.python.org/issue17911 | ||
msg237236 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2015-03-05 02:37 |
By the way, Robert Collins proposed the following change in part of #17911, but it was removed in the final change because asyncio must support Python 3.4 (and 3.3): diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 01320cd..08740aa 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -95,7 +95,7 @@ class Handle: info.append(_format_callback(self._callback, self._args)) if self._source_traceback: frame = self._source_traceback[-1] - info.append('created at %s:%s' % (frame[0], frame[1])) + info.append('created at %s:%s' % (frame.filename, frame.lineno)) return info def __repr__(self): | ||
msg297113 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2017-06-28 01:25 |
Sorry, I'm not interested anymore to work on asyncio, so I just close this old issue which has no activity since March 2015. I'm not even sure that it's doable to use traceback.TracebackException in asyncio. Moreover, Python and asyncio evolved in the meanwhile and the traceback logger was redesigned. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:13 | admin | set | github: 67775 |
2017-06-28 01:25:26 | vstinner | set | status: open -> closedresolution: out of datemessages: + stage: resolved |
2015-03-05 02:37:00 | vstinner | set | messages: + |
2015-03-05 02:34:31 | vstinner | set | messages: + |
2015-03-05 02:33:28 | vstinner | create |