Skip to main content

Simple handling mutexes with pywin32

Project description

WinMutex

A simple Python library to create and manage Windows mutexes.

Installation

You can install the library using pip:

pip install winmutex

Usage

Basic Example

from winmutex import WindowsMutex

mutex = WindowsMutex("anidev/winmutex/simple", True)  # Name may be any string
mutex.timeout = 2500  # Set a timeout of 2.5 seconds

with mutex:
    print(f"[I] Mutex({mutex}) acquired.")
    input("Enter to release the mutex and exit> ")

print(f"[I] Mutex({mutex}) released. Exiting...")

Legacy

from winmutex import WindowsMutex

mutex = WindowsMutex("anidev/winmutex/acquire", True)  # Name may be any string

if not mutex.acquire(5000):  # Acquire the mutex with a timeout of 5 seconds; None for no timeout
    print(f"[W] Mutex({mutex}) already exists or acquire timeout exceeded.")
    exit(1)

# Do some work while holding the mutex

print(f"[I] Mutex({mutex}) acquired.")
input("Enter to release the mutex and exit> ")

# Release the mutex
mutex.release()
print(f"[I] Mutex({mutex}) released. Exiting...")

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

winmutex-1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

winmutex-1.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file winmutex-1.0.1.tar.gz.

File metadata

  • Download URL: winmutex-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for winmutex-1.0.1.tar.gz
Algorithm Hash digest
SHA256 826317aa5c3eedea37bdb3fb908a162a2d086034a4a4b5d5ac3be9d0d0b2dd23
MD5 8ea0c88e5d8b3f791fda5f2690e063de
BLAKE2b-256 aaf6ce2f70f42af21ddb17df346462653463b4aacc2f643ce99327f83fb02bf6

See more details on using hashes here.

File details

Details for the file winmutex-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: winmutex-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for winmutex-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92a07437c533913947193384c0f5db159aff1b71bff621c1b481869ccb765a47
MD5 641356d52c19fabe99a4c48cd46d023e
BLAKE2b-256 62fe9c8dd0db7f3ffe235f758c9bed1d4d42e92e461a0dd1bb0992d81113174e

See more details on using hashes here.

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