- with.py: basic context manager using
with - with-as.py: combine
withwithas - with-exception.py: exception handle in
with - with-async.py: An asynchronous context manager is a context manager that is able to suspend execution in its enter and exit methods.
- context_lib.py: a decorator that can be used to define a factory function for with statement context managers, without needing to create a class or separate
__enter__()and__exit__()methods. - context_lib_decorator.py: A base class that enables a context manager to also be used as a decorator.
- context_lib_exitstack.py: ExitStack makes it possible to instead register a callback for execution at the end of a with statement, and then later decide to skip executing that callback:
- context_lin_reentrant.py: Reentrant context managers can not only be used in multiple with statements, but may also be used inside a with statement that is already using the same context manager.