On Fri, Nov 10, 2017 at 9:52 PM, Chris Jerdonek
<chris.jerdo...@gmail.com> wrote:
> Hi, I recently encountered a situation with asyncio where the stack
> trace is getting truncated: an exception isn't getting chained as
> expected.
>
> I was able to reduce it down to the code below.
>
> The reduced case seems like a pattern that can come up a lot, and I
> wasn't able to find an issue on the CPython tracker, so I'm wondering
> if I'm doing something wrong or if the behavior is deliberate.

I think what you're seeing is collateral damage from some known
bugginess in the generator/coroutine .throw() method:
https://bugs.python.org/issue29587

In trio I work around this by never using throw(); instead I send() in
the exception and re-raise it inside the coroutine:
https://github.com/python-trio/trio/blob/389f1e1e01b410756e2833cffb992fd1ff856ae5/trio/_core/_run.py#L1491-L1498

But asyncio doesn't do this -- when an asyncio.Task awaits an
asyncio.Future and the Future raises, the exception is throw()n into
the Task, triggering the bug:
https://github.com/python/cpython/blob/e184cfd7bf8bcfd160e3b611d4351ca3ce52d9e2/Lib/asyncio/tasks.py#L178

(If you try profiling your code you may also see weird/impossible
results in cases like this, because throw() also messes up stack
introspection.)

-n

-- 
Nathaniel J. Smith -- https://vorpus.org
_______________________________________________
Async-sig mailing list
Async-sig@python.org
https://mail.python.org/mailman/listinfo/async-sig
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to