/namedmutex

namedmutex.py, a simple ctypes wrapper for Win32 named mutexes

Primary LanguagePython

namedmutex.py, a simple ctypes wrapper for Win32 named mutexes

NamedMutex is a class for using Windows (Win32) named mutexes for system-wide locks. For example, we use these to lock system-wide log files that multiple processes can write to.

This has a similar API to threading.Lock, and can be used with Python's with statement.

For example:

with namedmutex.NamedMutex('get_dir_mutex'):
    latest_dir = get_latest_dir()
    os.rename(latest_dir, latest_dir + '-processing')

See the source code for more info!