Skip to main content

A flock implementation using Python's context manager.

Project description

Flock with Context Manager

A flock implementation using Python's context manager.

Installation

pip3 install flock-context-manager

Usage

"""Demonstration script for flock with context manager"""

from multiprocessing import Pool
from os import getpid
from time import sleep

from flock_context import FLockContext

LOCK_FILE = "demo.lock"


def task():
    """Your mutually exclusive task goes here"""

    pid = getpid()

    print(f"[{pid}] Getting Lock")
    with FLockContext(LOCK_FILE):
        print(f"[{pid}] Lock Obtained - sleeping for 2 seconds")
        sleep(2)
    print(f"[{pid}] Lock Released")


if __name__ == "__main__":
    print("Starting")
    with Pool(3, task) as pool:
        pool.close()
        pool.join()
    print("Done")

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

flock_context_manager-1.0.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flock_context_manager-1.0.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file flock_context_manager-1.0.0.tar.gz.

File metadata

  • Download URL: flock_context_manager-1.0.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flock_context_manager-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3db23b74feff048ce4a98c18ca5d9cfb1a6f1ab021c28a1a375c1d171c23ceac
MD5 8debe0752b883985c4e114a8d0ab557a
BLAKE2b-256 b7f99d63844a30a5398fb8ac9504f84756d96c30d27fa5083f05c1aa45913d87

See more details on using hashes here.

Provenance

The following attestation bundles were made for flock_context_manager-1.0.0.tar.gz:

Publisher: release.yml on joepitt91/flock-context

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flock_context_manager-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flock_context_manager-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5195c18473a7e9ca7e9c688ffcc3ac98aeec0f4b060b3b6cf2df3fa89773cb03
MD5 21c7650ef020876dfeaac7efe4339629
BLAKE2b-256 6cc523162802a471880bd12b0b4595419dde6ac2450b1a8e0873922a8ca13d74

See more details on using hashes here.

Provenance

The following attestation bundles were made for flock_context_manager-1.0.0-py3-none-any.whl:

Publisher: release.yml on joepitt91/flock-context

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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