Giter Site home page Giter Site logo

Comments (5)

CoolCat467 avatar CoolCat467 commented on August 21, 2024

For line number debugging purposes, which exact version of Trio are you using? For example, on my machine, I can do this to get the version:

>>> import trio
>>> trio.__version__
'0.26.0'

from trio.

A5rocks avatar A5rocks commented on August 21, 2024

Nevermind I misread this issue.

from trio.

yang avatar yang commented on August 21, 2024

0.22.2

from trio.

CoolCat467 avatar CoolCat467 commented on August 21, 2024

I've got this based off your minimal example:

from __future__ import annotations

import trio

from contextlib import asynccontextmanager, AbstractAsyncContextManager
from collections.abc import Callable, AsyncGenerator
from typing import TypeVar


T = TypeVar("T")


@asynccontextmanager
async def par_w(a: Callable[[], AbstractAsyncContextManager[T]]) -> AsyncGenerator[T, None]:
    ca = a()
    value = await ca.__aenter__()
    yield value
    await ca.__aexit__(None, None, None)


async def run() -> None:
    context_manager = trio.open_nursery
    async def do_three() -> None:
        print("3 start")
        await trio.sleep(1)
        print("3 end")
    async with par_w(context_manager) as nursery:
        print("1")
        await trio.sleep(1)
        print("2")
        nursery.start_soon(do_three)
        print("end")
    print("4")


if __name__ == "__main__":
    trio.run(run)

and I don't see any errors happening, so I'm guessing it's an issue with whatever async context manager you are passing in as a to your par_w function. If you could share what that is that would be great.

from trio.

TeamSpen210 avatar TeamSpen210 commented on August 21, 2024

The issue here is similar to the async generator issue. Because you're calling with statement methods directly, you have to be incredibly careful to preserve the nesting order. Otherwise, Trio's internal cancel scope stack can get messed up, breaking everything.

It's probably best to avoid calling them directly, instead use ExitStack, or put things in different tasks for concurrency.

from trio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.