changed lock.acquire(), lock.release() to with lock: