Skip to main content

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.

Release files for winmutex 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for winmutex 1.0.1
File Size Uploaded
winmutex-1.0.1.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for winmutex 1.0.1
File Interpreter ABI Platform
winmutex-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / winmutex-1.0.1.tar.gz

Download URL winmutex-1.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
826317aa5c3eedea37bdb3fb908a162a2d086034a4a4b5d5ac3be9d0d0b2dd23
BLAKE2b-256 checksum
How to use checksums
aaf6ce2f70f42af21ddb17df346462653463b4aacc2f643ce99327f83fb02bf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.2 Windows/11

Release files / winmutex-1.0.1-py3-none-any.whl

Download URL winmutex-1.0.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92a07437c533913947193384c0f5db159aff1b71bff621c1b481869ccb765a47
BLAKE2b-256 checksum
How to use checksums
62fe9c8dd0db7f3ffe235f758c9bed1d4d42e92e461a0dd1bb0992d81113174e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.2 Windows/11

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page