If you are using lock you should ALWAYS handle exceptions and release in in `try ... finally`, because now is function will raise an exception than lock will be never released and you will have to restart application.

You can also use `with` statement, which will also release lock in case of exception.