-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Our code for recovering after a "foreign await" needs to be reworked #552
Comments
For some context, I'm fine if what I'm trying to do is too esoteric to support, I just thought it would be interesting/cool to be able to use I'm mostly opening this issue in case it's of interest or an easy/obvious fix. |
Yes, trio_asyncio is the right place for this bug. No, you can't do that. You're still in a Trio context; the fact that you just started an asyncio loop doesn't change that. This code should work (warning, literal translation but untested): from functools import partial
async def f():
async with trio_asyncio.open_loop() as loop:
client = await loop.run_asyncio(partial(Client, asynchronous=True))
future = client.submit(lambda x: x + 1, 10)
return await loop.run_future(future) though you should be able to combine the last two lines to return await loop.run_asyncio(client.submit, lambda x: x + 1, 10) |
… and yes I need to improve error handling for this kind of mistake. |
That error message from trio's side is pretty bad too... in general we should probably tweak that (Re-opening so we don't forget these questions, though @smurfix may already know the answer.) |
The link from #882 just reminded me to look at this again, and I figured it out. Here's a minimal reproducer: import trio
import asyncio
async def f():
async with trio.open_nursery() as nursery:
nursery.start_soon(trio.sleep, float("inf"))
future = asyncio.Future()
await future
trio.run(f)
So I think we need to give up on the clever task-zapping trick. Other options:
|
thinking about this a bit more: Blowing up the whole program is by far the easiest thing to do, but unfortunately it means users don't get any info at all about where they We could like... recursively zap the whole task tree underneath the offending task... but this seems like a mess So... I guess that means we need to immediately resume the task by |
This improves debuggability (since the traceback points to the location of the error, rather than just the nursery whose task was at fault) and fixes python-trio#552 by ensuring we don't abandon the child tasks of the errant one.
Just doing some testing to see if I can use
dask.distributed
withtrio
&trio_asyncio
but have fallen at the first hurdle and hit aTrioInternalError
:Happy to move this to the
trio_asyncio
repo if that's a more appropriate place...The text was updated successfully, but these errors were encountered: