Re:Microsandbox: Virtual Machines that feel and perform like...
by appcypher on Friday May 30, 2025 @05:29PM
(#44140049)
Right. You can skip the `with` context manager and call start and stop yourself.
There is an example of that here:
https://github.com/microsandbox/microsandbox/blob/0c13fc27ab...
Re:Microsandbox: Virtual Machines that feel and perform like...
by gcharbonnier on Friday May 30, 2025 @05:39PM
(#44140116)
async with is just syntactic sugar. You could very well call __aenter__ and __aexit__ manually. You could also use an AsyncExitStack, call __aenter__ manually, then enter_async_context, and call aclose when you’re done. Since aclose method exists I guess this is not an anti-pattern.
https://docs.python.org/3/library/contextlib.html#contextlib...
The documented code pattern is this:
Due to the way my code works I want to instantiate the sandbox once for a specific class and then have multiple calls to it by class methods, which isn't a clean fit for that "async with" pattern.Any recommendations?