Lock

Python's Lock is the equivalent of a Mutex and this lesson looks at its various uses.

We'll cover the following...

Lock

Lock is the most basic or primitive synchronization construct available in Python. It offers two methods: acquire() and release(). A Lock object can only be in two states: locked or unlocked. A Lock object can only be unlocked by a thread that locked it in the first place.

A Lock object is equivalent of a mutex that you read about in operating systems theory.

Acquire

Whenever a Lock object is created it is initialized with the unlocked state. Any thread can invoke acquire() on the lock object to lock it. Advanced readers should ...