hpcugent / VSC-tools

Website for VSC-tools, common tools used within our organization.
http://hpcugent.github.com/VSC-tools
0 stars 4 forks source link

Convert vsc.utils.cache to use the with semantics. #39

Open piojo-zz opened 11 years ago

piojo-zz commented 11 years ago

It is much simpler to use the FileCache module if we can do just like with any other file:

with vsc.utils.cache("foo") as f:
    f.load("some_key")
    # yabbadabba

Instead of

try:
    f = vsc.utils.cache("foo")
    try:
        f.load("some_key")
        # yabbadabba
    except Something, err:
        pass
    finally:
        pass
except SomethingElse, err2:
    pass

Our main users for this module are SL6 boxes, where the __enter__/__exit__ protocol is supported.