Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Decorator for tagging critical sections locking them out

Project description

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 @LockoutTagout(tag), 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]

def readData1(sharedData):
    for val in sharedData:

def writeData1(sharedData):
    for i in range(0, 3):
        sharedData[i] += 1

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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for loto, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size loto-0.1.5-py3-none-any.whl (4.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size loto-0.1.5.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page