We should remove the lock even if there's an exception thrown. I think this needs to be in a try: finally: statement.

If you add that, can you also put the rmtree() in there as well to clean things up appropriately after an exception