Decorator for tagging critical sections locking them out
loto : Lockout-Tagout
Loto provides a simple decorator for functions that need to access critical sections with mutex locks.
When you decorate a function with
the function call will block until it can acquire a mutex lock
shared between all functions with the same tag.
from loto import LockoutTagout from threading import Thread from random import random from time import sleep data = [1, 2, 3] @LockoutTagout('data1') def readData1(sharedData): for val in sharedData: print(val) sleep(random()) @LockoutTagout('data1') def writeData1(sharedData): for i in range(0, 3): sharedData[i] += 1 sleep(random()) for i in range(0, 5): Thread(target=readData1, args=(data,)).start() Thread(target=writeData1, args=(data,)).start()
These two functions will lockout-tagout with the same tag, so they will acquire a lock managed by this decorator class before they're executed. This means that no two functions with the same tag can be executing concurrently.
One mutex lock is managed per unique tag.
You can install this module from PyPI with
pip install loto
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size loto-0.1.4-py3-none-any.whl (4.2 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size loto-0.1.4.tar.gz (2.9 kB)||File type Source||Python version None||Upload date||Hashes View|