Skip to content

Instantly share code, notes, and snippets.

@koi8-r
Created October 4, 2021 14:42
Show Gist options
  • Save koi8-r/dbf9330883a99ce7021f67936f011d2c to your computer and use it in GitHub Desktop.
Save koi8-r/dbf9330883a99ce7021f67936f011d2c to your computer and use it in GitHub Desktop.
def lock(res):
pass
def free(res):
pass
class MyCtx(object):
__slots__ = ('res',)
def __init__(self, res):
self.res = res
def __enter__(self):
lock(self.res)
return self.res
def __exit__(self, clazz, ex, tb):
free(self.res)
if not 'no-suppress':
return True
if __name__ == '__main__':
with MyCtx('World') as it, MyCtx('Anybody') as anybody:
print(f"Hello, {it} !")
print(f"Hello, {anybody} !")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment