Same comment as above.  I would suggest use of with lock:.