Processes Locks: Multiprocessing Locks

Learn about process locks using multiprocessing.

When all programs accessing a shared resource are written in Python, the natural method to secure accesses is to use the multiprocessing.Lock objects provided by Python. That class is built around POSIX or Windows semaphores (depending on your operating system) and allows use of a lock across several processes.

Example 1: Multiprocessing with no lock

To run the application below, click Run and run the command python multiprocessing-lock-nolock.py.

Get hands-on with 1400+ tech skills courses.