瀏覽代碼

[minor] add locking to scheduler

version-14
Pratik Vyas 11 年之前
committed by Anand Doshi
父節點
當前提交
4090932fca
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. +3
    -2
      webnotes/utils/file_lock.py

+ 3
- 2
webnotes/utils/file_lock.py 查看文件

@@ -6,6 +6,7 @@ class LockTimeoutError(Exception):
pass pass


def create_lock(name): def create_lock(name):
pre
lock_path = get_lock_path(name) lock_path = get_lock_path(name)
if not check_lock(lock_path): if not check_lock(lock_path):
return touch_file(lock_path) return touch_file(lock_path)
@@ -20,14 +21,14 @@ def touch_file(path):
def check_lock(path): def check_lock(path):
if not os.path.exists(path): if not os.path.exists(path):
return False return False
if time() - os.path.getmtime(path) > 600:
if time() - os.path.mtime(path) > 600:
raise LockTimeoutError(path) raise LockTimeoutError(path)
return True return True


def delete_lock(name): def delete_lock(name):
lock_path = get_lock_path(name) lock_path = get_lock_path(name)
try: try:
os.remove(lock_path)
os.remove(path)
except OSError: except OSError:
pass pass
return True return True


Loading…
取消
儲存