Created
October 4, 2021 14:42
-
-
Save koi8-r/dbf9330883a99ce7021f67936f011d2c 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
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