From a1b060933276d60b96fe30bc9f4530dc486561fe Mon Sep 17 00:00:00 2001 From: Tlams Date: Thu, 8 Feb 2018 16:12:38 +0000 Subject: [PATCH] lock file library to prevent duplicates tasks --- code/scripts/main/core/libs/locker.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 code/scripts/main/core/libs/locker.py diff --git a/code/scripts/main/core/libs/locker.py b/code/scripts/main/core/libs/locker.py new file mode 100644 index 0000000..bac66a5 --- /dev/null +++ b/code/scripts/main/core/libs/locker.py @@ -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)) \ No newline at end of file