Skip to content

Instantly share code, notes, and snippets.

@whitekid
Created June 3, 2016 07:40
Show Gist options
  • Save whitekid/e3a821509cca0df782431ef313a4a1a2 to your computer and use it in GitHub Desktop.
Save whitekid/e3a821509cca0df782431ef313a4a1a2 to your computer and use it in GitHub Desktop.
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