Skip to main content

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.

Example

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.

Installation

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.

Source Distribution

loto-0.1.5.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

loto-0.1.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file loto-0.1.5.tar.gz.

File metadata

  • Download URL: loto-0.1.5.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for loto-0.1.5.tar.gz
Algorithm Hash digest
SHA256 605ceb33136ed002179362ea7653ffeee422208a8da399546be165abb8c51470
MD5 9a1c2c4f3e3dd7f2d0ff236e4b510e84
BLAKE2b-256 31edf4ef2968888f1ffa41eed7bee8e090d2122f9f3c622342b2e1ebfbf9ab4c

See more details on using hashes here.

File details

Details for the file loto-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: loto-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for loto-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc11527ab765864c8203f3f9aa57b3ee3e6fe0bd7e35b4d833b96a0aa7cf028
MD5 80966a15bef8b8fc0d18966a501409fb
BLAKE2b-256 0be65ae9d6988d627dcf4c87c8d5b649426f2722c71a22a8292041ac9c89659b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page