In brief
threading.Lock protects a critical section among threads using the same lock. It prevents incompatible steps from changing shared state concurrently.
Useful to know
threading.Lock protects a critical section among threads using the same lock. It prevents incompatible steps from changing shared state concurrently. [1]
For a check followed by an update, protect the necessary sequence rather than only its final line. Avoid holding a lock around unnecessarily slow work. A Lock in one method does not protect another access path that never uses it.
Sources
For further detail and to check the information: