This commit is contained in:
zhouwy2115 2020-04-08 20:03:01 +08:00 committed by Dun Liang
parent c8631449a8
commit 1bd4f9e944
1 changed files with 3 additions and 3 deletions

View File

@ -5,15 +5,15 @@ from jittor_utils import cache_path
class Lock: class Lock:
def __init__(self, filename): def __init__(self, filename):
self.handle = open(filename, 'w') self.handle = open(filename, 'w')
print(f'创建锁 {filename}') print(f'创建锁 {filename} PID {os.getpid()}')
def lock(self): def lock(self):
ret = fcntl.flock(self.handle, fcntl.LOCK_EX) ret = fcntl.flock(self.handle, fcntl.LOCK_EX)
print(f'加锁成功 {ret}') print(f'加锁成功 {ret} PID {os.getpid()}')
def unlock(self): def unlock(self):
ret = fcntl.flock(self.handle, fcntl.LOCK_UN) ret = fcntl.flock(self.handle, fcntl.LOCK_UN)
print(f'释放锁成功 {ret}') print(f'释放锁成功 {ret} PID {os.getpid()}')
def __del__(self): def __del__(self):
self.handle.close() self.handle.close()