Closed software-opal closed 6 years ago
aiotools already has a similar functionality: AsyncContextGroup
.
While contextlib.ExitStack
is for sequentially stacking multiple context managers, aiotools.AsyncContextGroup
executes enter/exit handlers of multiple async context managers concurrently using asyncio.gather
.
It may be useful to have a sequential equivalent of ExitStack
but I don't see the enough motivation because it does not exploit asynchrony.
Please bring me a motivating example for that. :)
In the standard library there is
contextlib.ExitStack
which allows multiple context managers to be applied one inside the other such that a failure of an__enter__
method calls the__exit__
methods.If this could be implemented in such a way that it would allow for both sync and async context managers to be called; and called inside to out with appropriate error handling.