Message367832
| Author |
chris.jerdonek |
| Recipients |
asvetlov, chris.jerdonek, yselivanov |
| Date |
2020年05月01日.09:57:11 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1588327031.68.0.391066617052.issue40466@roundup.psfhosted.org> |
| In-reply-to |
| Content |
This issue is about how if a coroutine is wrapped in a Task with asyncio.ensure_future(), then portions of the exception chain can be lost.
Specifically, if you run the following code, then ValueError will be raised with exc.__context__ equal to the KeyError:
import asyncio
async def raise_error():
raise ValueError
async def main():
try:
raise KeyError
except Exception as exc:
future = raise_error()
# Uncommenting the next line makes exc.__context__ None below.
# future = asyncio.ensure_future(future)
try:
await future
except Exception as exc:
print(f'error: {exc!r}, context: {exc.__context__!r}')
raise
asyncio.get_event_loop().run_until_complete(main())
However, if you uncomment the `asyncio.ensure_future()` line, then the ValueError will be raised with no __context__.
I originally raised this issue a couple years ago here:
https://mail.python.org/pipermail/async-sig/2017-November/000403.html
There it was suggested that this was a special case of this issue:
https://bugs.python.org/issue29587
However, after writing code to fix that, this issue still exists. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2020年05月01日 09:57:11 | chris.jerdonek | set | recipients:
+ chris.jerdonek, asvetlov, yselivanov |
| 2020年05月01日 09:57:11 | chris.jerdonek | set | messageid: <1588327031.68.0.391066617052.issue40466@roundup.psfhosted.org> |
| 2020年05月01日 09:57:11 | chris.jerdonek | link | issue40466 messages |
| 2020年05月01日 09:57:11 | chris.jerdonek | create |
|