Use of with statement for adquiring the lock