Skip to content

TrioInternalError on trio.run(agen.__anext__) #1191

@njsmith

Description

@njsmith

Here's a strange crash, discovered by @florimondmanca in encode/httpx#214:

import trio
async def gen():
    yield "hi"
trio.run(gen().__anext__)

Results in:

Traceback (most recent call last):
  File "/tmp/asdf.py", line 6, in <module>
    trio.run(gen().__anext__)
  File "/home/njs/.user-python3.7/lib/python3.7/site-packages/trio/_core/_run.py", line 1769, in run
    run_impl(runner, async_fn, args)
  File "/home/njs/.user-python3.7/lib/python3.7/site-packages/trio/_core/_run.py", line 1918, in run_impl
    runner.task_exited(task, final_outcome)
  File "/home/njs/.user-python3.7/lib/python3.7/site-packages/trio/_core/_run.py", line 1404, in task_exited
    raise TrioInternalError
trio.TrioInternalError

Poking around, I see that init has set self.main_task_outcome before exiting:

(Pdb) p self.main_task_outcome
Error(AttributeError("'async_generator_asend' object has no attribute 'cr_frame'"))

So this is another variant of #550.

This is a pretty weird thing to do, so I guess this issue isn't super urgent, but two todo items:

  • The error message is really bad... there are several measures in place here to try to make the error come out, and they all failed. The run loop tries to reveal exceptions from init, but init exited successfully. It did this after setting self.main_task_exited... but even though spawn_impl failed, it didn't fail until after adding the new task to self.tasks, so run freaked out instead of re-raising self.main_task_exited. I guess we should move the self.tasks assignment down even further in spawn_impl?

  • Also, this probably shouldn't crash! And Support Cython-based async functions #550 has another set of reasons to support it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions