Easy file exclusive locking tool based on file rename
Project description
rename_lock
下の方に日本語の説明があります
Overview
- Easy file exclusive locking tool based on file rename.
Usage
- While you are in "WITH" area, the file is locked and cannot be edited by any other process.
- While locked, the file will be renamed to "original_name.locked"
- The name can be obtained with rlock.filename
with rename_lock("./demo_file.txt") as rlock:
# operation on locked file
temp_filename = rlock.filename # temporary file name
with open(temp_filename, "w") as f:
f.write("something")
-
About Unlocking
- The lock is automatically unlocked when exiting "WITH" area.
- Also, when using "WITH", it will automatically unlock when stopped due to an error or when stopped by ctrl+C.
- However, there may be cases where the file is not unlocked, such as when the entire window is erased.
-
The following is how to write when not using "WITH".
# method without "with" syntax
rlock = rename_lock("./demo_file.txt")
print(rlock.filename)
rlock.unlock()
概要
- 手軽なファイルの排他ロックツール
- ファイルの名称変更を動作原理とする
- 説明は執筆中です
使用例
- 下記のように、with内にいる間ファイルの編集がロックされます
- ロック中はファイルは「元の名前.locked」という名前に変更されます
- その名前はrlock.filenameで取得できます
with rename_lock("./demo_file.txt") as rlock:
# operation on locked file
temp_filename = rlock.filename # temporary file name
with open(temp_filename, "w") as f:
f.write("something")
-
ロック解除について
- withを抜けると自動的にロック解除されます
- また、エラーによる停止やctrl+Cによる停止時にも、withを使っている場合は自動的にロック解除されます
- ただし、ウィンドウごと消した場合など、ロック解除されない場合もあります
-
下記はwithを使わない場合の書き方です
# method without "with" syntax
rlock = rename_lock("./demo_file.txt")
print(rlock.filename)
rlock.unlock()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rename-lock-0.0.2.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for rename_lock-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e21c384b3d9a5f6d6e2a3961246ba270570e682ce54ef302d315db9b7571d2e1 |
|
MD5 | b3877577a42159ae868ee15964ba1265 |
|
BLAKE2b-256 | b4e47294dc5b0c3bea861f5fb41cd46386d0e7255b1ff18c0297dc22c911e704 |