@@ -839,6 +839,7 @@ def lock(
839839 blocking_timeout : Optional [float ] = None ,
840840 lock_class : Optional [Type [Lock ]] = None ,
841841 thread_local : bool = True ,
842+ raise_on_release_error : bool = True ,
842843 ) -> Lock :
843844 """
844845 Return a new Lock object using key ``name`` that mimics
@@ -885,6 +886,11 @@ def lock(
885886 thread-1 would see the token value as "xyz" and would be
886887 able to successfully release the thread-2's lock.
887888
889+ ``raise_on_release_error`` indicates whether to raise an exception when
890+ the lock is no longer owned when exiting the context manager. By default,
891+ this is True, meaning an exception will be raised. If False, the warning
892+ will be logged and the exception will be suppressed.
893+
888894 In some use cases it's necessary to disable thread local storage. For
889895 example, if you have code where one thread acquires a lock and passes
890896 that lock instance to a worker thread to release later. If thread
@@ -902,6 +908,7 @@ def lock(
902908 blocking = blocking ,
903909 blocking_timeout = blocking_timeout ,
904910 thread_local = thread_local ,
911+ raise_on_release_error = raise_on_release_error ,
905912 )
906913
907914
0 commit comments