From 5dfde1ec3377a3738f4f575b12d137cc4e2e39d0 Mon Sep 17 00:00:00 2001 From: shenyuhan Date: Tue, 24 Sep 2019 17:12:21 +0800 Subject: [PATCH] add fake windows dependency fcntl --- paddlehub/common/lock.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/paddlehub/common/lock.py b/paddlehub/common/lock.py index ea44f0a3..531b990a 100644 --- a/paddlehub/common/lock.py +++ b/paddlehub/common/lock.py @@ -1,5 +1,6 @@ -import fcntl import os +if os.name == "posix": + import fcntl class WinLock(object): @@ -15,23 +16,22 @@ class Lock(object): _owner = None def __init__(self): - self.LOCK_EX = fcntl.LOCK_EX - self.LOCK_UN = fcntl.LOCK_UN - self.LOCK_TE = "" if os.name == "posix": self.lock = fcntl else: self.lock = WinLock() _lock = self.lock + self.LOCK_EX = self.lock.LOCK_EX + self.LOCK_UN = self.lock.LOCK_UN def get_lock(self): return self.lock def flock(self, fp, cmd): - if cmd == fcntl.LOCK_UN: + if cmd == self.lock.LOCK_UN: Lock._owner = None self.lock.flock(fp, cmd) - elif cmd == fcntl.LOCK_EX: + elif cmd == self.lock.LOCK_EX: if Lock._owner is None: Lock._owner = os.getpid() self.lock.flock(fp, cmd) @@ -43,3 +43,4 @@ class Lock(object): lock = Lock() + -- GitLab