summaryrefslogtreecommitdiff
path: root/jimbrella/lockfile.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-02-06 15:11:01 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-02-06 15:11:01 +0800
commit7a110edc2529111077351c31f4414849de5515d3 (patch)
tree3751792e782f4dbf4815d9f2a16a93caeca3596d /jimbrella/lockfile.py
parenteb743fbca3554e8c29588a6d50b56e27e9cdc342 (diff)
Migrate AdminLog to sqlite
Diffstat (limited to 'jimbrella/lockfile.py')
-rw-r--r--jimbrella/lockfile.py33
1 files changed, 0 insertions, 33 deletions
diff --git a/jimbrella/lockfile.py b/jimbrella/lockfile.py
deleted file mode 100644
index 987f0e3..0000000
--- a/jimbrella/lockfile.py
+++ /dev/null
@@ -1,33 +0,0 @@
-import os
-
-
-class Lockfile:
- """Prevent unwanted concurrency for file I/O.
-
- For a file named "<file>", create or remove a lockfile named "<file>.lock".
-
- When a process is modifying the file, call `lock(). When the modification
- is done, call `unlock()`.
- """
-
- def __init__(self, filepath):
- self.filepath = str(filepath)
- self.lockpath = self.filepath + ".lock"
-
- def lock(self):
- """Continue attempting to lock until locked."""
- locked = False
- while not locked:
- try:
- f = open(self.lockpath, "x")
- f.close()
- locked = True
- except FileExistsError:
- continue
-
- def unlock(self):
- """Remove lockfile."""
- try:
- os.remove(self.lockpath)
- except FileNotFoundError:
- return