Skip to main content

filelock ,it can run on linux and windows

Project description

1. pip install nb_filelock

基于代码所在机器的跨进程 跨(jvm)解释器的文件互斥锁。兼容windwos和linux

filelock,which can run on linux and windwos.

比如希望在当前机器只能同时运行某一个代码块,完全豪不相关的两次启动xx.py,没有办法使用进程锁,
压根就不是使用multiprossing包同时启动的多个子进程而是手动两次运行了python xx.py,
好的方式是使用redis分布式锁,可以保证所有机器只提示一个获得锁,但如果没安装redis切要保证当前机器只有一个能执行代码块,
则使用此锁

测试例子。

把下面的python文件复制到一个文件中叫test.py,然后重复启动两次 python test.py,
当第一个脚本还没执行完代码块时候,另一个脚本会等待第一个脚本执行完成代码块的语句才会开始print hi。
import nb_log
import time
from nb_filelock import FileLock

print('wait filelock')
with FileLock('testx.lock'):
    print('hi')
    time.sleep(20)
    print('hello')

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

nb_filelock-0.2.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file nb_filelock-0.2.tar.gz.

File metadata

  • Download URL: nb_filelock-0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.6

File hashes

Hashes for nb_filelock-0.2.tar.gz
Algorithm Hash digest
SHA256 02c1f3ee5bd45386b2a05eaadea2e2124cfd145df8f292bb45ac40d128c08d13
MD5 3c33b02b957a7d0a4cfd8bb1abbf6638
BLAKE2b-256 654bceccaa111e4cf3ef1b8350bb01e616cfa9adc77b0ed68b05414623735089

See more details on using hashes here.

Provenance

Supported by

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