smpl.plot.ExitStack¶
- class smpl.plot.ExitStack[source]¶
Bases:
_BaseExitStack,AbstractContextManagerContext manager for dynamic management of a stack of exit callbacks.
- For example:
- with ExitStack() as stack:
files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list raise an exception.
- __init__()¶
Methods
__init__()callback(callback, /, *args, **kwds)Registers an arbitrary callback and arguments.
close()Immediately unwind the context stack.
enter_context(cm)Enters the supplied context manager.
pop_all()Preserve the context stack by transferring it to a new instance.
push(exit)Registers a callback with the standard __exit__ method signature.
- callback(callback, /, *args, **kwds)¶
Registers an arbitrary callback and arguments.
Cannot suppress exceptions.
- enter_context(cm)¶
Enters the supplied context manager.
If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method.
- pop_all()¶
Preserve the context stack by transferring it to a new instance.
- push(exit)¶
Registers a callback with the standard __exit__ method signature.
Can suppress exceptions the same way __exit__ method can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself).