mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
lock file library to prevent duplicates tasks
This commit is contained in:
parent
e79ca6c1f5
commit
a1b0609332
1 changed files with 19 additions and 0 deletions
19
code/scripts/main/core/libs/locker.py
Normal file
19
code/scripts/main/core/libs/locker.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import os
|
||||
|
||||
class locker:
|
||||
def createlock(self, lockfile, date=0):
|
||||
try:
|
||||
if os.path.exists(lockfile):
|
||||
f = open(lockfile, "r+")
|
||||
return f.read()
|
||||
else:
|
||||
f = open(lockfile, "w")
|
||||
f.write(date)
|
||||
except BaseException as e:
|
||||
raise("Can't create or read the lock file: {0}".format(e))
|
||||
|
||||
def unlock(self, lockfile):
|
||||
try:
|
||||
os.remove(lockfile)
|
||||
except BaseException as e:
|
||||
raise ("Can't delete the lock file: {0}".format(e))
|
Loading…
Add table
Add a link
Reference in a new issue