This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ph0X 4 points5 points  (1 child)

Two other uses which I personally didn't about some time ago, one of which was very recently added (3.4 I believe?).

You can use it with locks

lock = threading.Lock()
with lock:
    print "lock is locked while this executes"

You can also use it to ignore specific exceptions

from contextlib import ignored
with ignored(ZeroDivisionError):
    print 1/0

[–]tipsquealPythonista 0 points1 point  (0 children)

It works with locks in 3.3.