Python - Context Managers
You want to safely acquire and release a lock using automatic resource cleanup. Which code snippet correctly uses
with for this purpose?import threading
lock = threading.Lock()
# Choose the correct usage
A) with lock.acquire():
print('Lock acquired')
B) with lock.acquire:
print('Lock acquired')
C) with lock:
print('Lock acquired')
D) with lock.lock():
print('Lock acquired')