We can save many lines, and so reducing the code complexity and readability, by implementing a context manager for the Lock base class.
The current code:
self._lock.acquire() try: # ... finally: self._lock.release()
Will be usable this way:
with self._lock: # ...
Pros:
- resources are always closed and garbaged;
- readability;
- less code;
- more pythonic;
- possibility to use the context manager or not;
- implementation time is quite small and not complex.
Cons:
- None.