Created
June 3, 2016 07:40
-
-
Save whitekid/e3a821509cca0df782431ef313a4a1a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import functools | |
class Defer(contextlib.ExitStack): | |
def __call__(self, *args, **kwargs): | |
self.callback(functools.partial(*args, **kwargs)) | |
def __del__(self): | |
self.close() | |
def main(): | |
defer = Defer() | |
print('enter main') | |
defer(print, 'deferred') | |
print('exit main') | |
main() | |
print('exit prog') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment