From the course: Python Parallel and Concurrent Programming Part 1
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Read-write lock: Python demo - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
Read-write lock: Python demo
- Reader-writer locks are a common feature in many programming languages that support concurrency, however they're not included by default in Python. When I need something that isn't standard in Python, my first stop is always the Python package index at pypi.org and sure enough, someone has already implemented a reader-writer lock package for python. I'll install it for this demonstration using the Python package manager with the console command pip install reader writer lock. And it's that easy. In this example program, we create 10 threads to concurrently read what day it is from a shared calendar while two other threads update it. The calendar here is just a list of strings to represent the seven days of the week on line six, as well as an integer to indicate which day today is on line seven. I've created a single regular lock object named marker on line eight which all of the threads will use to enforce mutual…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.