提交 5dfde1ec 编写于 作者: S shenyuhan

add fake windows dependency fcntl

上级 3e4c1e6a
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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册