Skip to content
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

run_fn_as_system_task does not account for nested Trio #2191

Open
mastercoms opened this issue Dec 8, 2021 · 0 comments · May be fixed by #2535
Open

run_fn_as_system_task does not account for nested Trio #2191

mastercoms opened this issue Dec 8, 2021 · 0 comments · May be fixed by #2535

Comments

@mastercoms
Copy link

I'm new to Trio, so forgive me if I get the terminology wrong. This check for deadlock only checks if there is a Trio task at all, not that the task is the same as the caller. So, if we have something like this:

from concurrent.futures import as_completed
from anyio.from_thread import start_blocking_portal

async def endpoint():
  with start_blocking_portal() as portal:
    futures = [portal.start_task_soon(long_running_task, i) for i in range(1, 5)]
    for future in as_completed(futures):
        print(future.result())

It will fail and exit the portal prematurely because endpoint is running in Trio, but the portal is a different Trio task. The check sees if there's a task at all, rather than checking if the call would actually deadlock the task in the case of nesting.

If I remove the current task check, the portal runs successfully with no deadlock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant