##// END OF EJS Templates
lock: refactor in preparation for next commit...
Valentin Gatien-Baron -
r44107:cd822413 default
parent child Browse files
Show More
@@ -330,27 +330,32 b' class lock(object):'
330 return None
330 return None
331 raise
331 raise
332
332
333 def _testlock(self, locker):
333 def _lockshouldbebroken(self, locker):
334 if locker is None:
334 if locker is None:
335 return None
335 return False
336 try:
336 try:
337 host, pid = locker.split(b":", 1)
337 host, pid = locker.split(b":", 1)
338 except ValueError:
338 except ValueError:
339 return locker
339 return False
340 if host != lock._host:
340 if host != lock._host:
341 return locker
341 return False
342 try:
342 try:
343 pid = int(pid)
343 pid = int(pid)
344 except ValueError:
344 except ValueError:
345 return locker
345 return False
346 if procutil.testpid(pid):
346 if procutil.testpid(pid):
347 return False
348 return True
349
350 def _testlock(self, locker):
351 if not self._lockshouldbebroken(locker):
347 return locker
352 return locker
353
348 # if locker dead, break lock. must do this with another lock
354 # if locker dead, break lock. must do this with another lock
349 # held, or can race and break valid lock.
355 # held, or can race and break valid lock.
350 try:
356 try:
351 l = lock(self.vfs, self.f + b'.break', timeout=0)
357 with lock(self.vfs, self.f + b'.break', timeout=0):
352 self.vfs.unlink(self.f)
358 self.vfs.unlink(self.f)
353 l.release()
354 except error.LockError:
359 except error.LockError:
355 return locker
360 return locker
356
361
General Comments 0
You need to be logged in to leave comments. Login now