Skip to main content
#local_mutex
本地锁,通过fcntl针对文件加锁实现的. 需要强烈注意的是,多线程下是无效的,原因? [查看链接](http://xiaorui.cc)

#Usage:

最简单的例子,适合一个程序同时跑一个的场景.
```
import sys
from local_mutex import LocalMutex

try:
lock = LocalMutex('app.lock')
except LockError:
sys.exit('already running')

try:
print 'doing'
finally:
lock.release()
```

使用wait参数不停的试图获取Lock, 直到获取锁.
```
lock = LocalMutex('/var/run/app.lock', wait = True)
try:
print 'doing'
finally:
lock.release()
```

使用with关键词
```
with LocalMutex('app.lock', wait = True):
print 'doing'
```

如果是多线程环境,直接用threading的Lock
```
import threading
lock = threading.Lock()
with lock:
pass
```

Metadata

Release files for local_mutex 1.0

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

Source distribution (sdist)

Source distribution for local_mutex 1.0
File Size Uploaded Provenance
local_mutex-1.0.tar.gz 2.3 kB Without provenance Details

Release files / local_mutex-1.0.tar.gz

Download URL local_mutex-1.0.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c85ad5977629d97ce5b8715fe343bf04f3409b2bc8cf840dca7e00f1303549cc
BLAKE2b-256 checksum
How to use checksums
aa3f9d71f4992b5f55c662569bed5fbdbc9fe057f0ecc004dbb190caaa82219e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for local_mutex 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file No provenance

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