mirror of https://github.com/Jittor/Jittor
update
This commit is contained in:
parent
c8631449a8
commit
1bd4f9e944
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue