Consider code like this:
class SomeRunner:
def __init__(self) -> None:
self._stack: contextlib.AsyncExitStack | None = None
async def start(self) -> None:
stack = contextlib.AsyncExitStack()
await stack.enter_async_context(self.create_some_resource())
await stack.enter_async_context(self.use_some_resource())
self._stack = stack.pop_all()
async def stop(self) -> None:
await self._stack.aclose()
self._stack = None
The purpose of this class is to manage some async resource and long-running code using this resource together, and it seems to function fine. However, the SomeRunner task does not directly hold a reference to any Task, which makes me wonder: Is the long-running code being executed in danger of disappearing mid-execution,like a bare Task that has no strong reference?