I have an application that uses redis.lock.Lock (from the official redis-py package) a lot. It's either used directly by what I'm developing, or by other packages.
In rare cases, I end up with LockError (in case the application was restarted incorrectly, for example).
I manage to catch these Exceptions, but in the available attributes, there's only the error message, and not the name of the Lock (which would allow me to do a cleanup task).
Is there any way to add information to the LockError object, or how to find the Lock name from the within except block (bearing in mind that I can't modify the Lock implementation, or make a class that inherits it, as it's might be instantiated from code I don't own)?
Example of code:
try:
do_many_things_with_many_locks()
except LockError as le:
# How to retrieve which lock failed?
Given that you can't subclass and modify the
Lockimplementation, you can introspect the exception and retrieve name from theLockobject.For example,