Revision e6c200d6

b/lib/locking.py
377 377
    else:
378 378
      names.sort()
379 379

  
380
    # Now names contains a sorted list of resources whose lock we want to
381
    # acquire. In order to get them we loop on this (private) list and look
382
    # them up in __lockdict. Since we have no lock held on lockdict we have no
383
    # guarantees on their presence, and they may even disappear after we looked
384
    # them up. This is fine though as .acquire() itself is safe and will alert
385
    # us if the lock gets deleted.
386

  
380
    acquire_list = []
381
    # First we look the locks up on __lockdict. We have no way of being sure
382
    # they will still be there after, but this makes it a lot faster should
383
    # just one of them be the already wrong
387 384
    try:
388 385
      for lname in names:
389 386
        lock = self.__lockdict[lname] # raises KeyError if the lock is not there
387
        acquire_list.append((lname, lock))
388
    except (KeyError):
389
      raise errors.LockError('non-existing lock in set (%s)' % lname)
390

  
391
    # Now acquire_list contains a sorted list of resources and locks we want.
392
    # In order to get them we loop on this (private) list and acquire() them.
393
    # We gave no real guarantee they will still exist till this is done but
394
    # .acquire() itself is safe and will alert us if the lock gets deleted.
395
    try:
396
      for (lname, lock) in acquire_list:
390 397
        lock.acquire(shared=shared) # raises LockError if the lock is deleted
391 398
        try:
392 399
          # now the lock cannot be deleted, we have it!
......
398 405
          lock.release()
399 406
          raise
400 407

  
401
    except (KeyError, errors.LockError):
408
    except (errors.LockError):
402 409
      name_fail = lname
403 410
      for lname in self._list_owned():
404 411
        self.__lockdict[lname].release()

Also available in: Unified diff