Revision c6a622cf lib/locking.py
b/lib/locking.py | ||
---|---|---|
943 | 943 |
return self.__lockdict |
944 | 944 |
|
945 | 945 |
def is_owned(self): |
946 |
"""Is the current thread a current level owner?""" |
|
946 |
"""Is the current thread a current level owner? |
|
947 |
|
|
948 |
@note: Use L{check_owned} to check if a specific lock is held |
|
949 |
|
|
950 |
""" |
|
947 | 951 |
return threading.currentThread() in self.__owners |
948 | 952 |
|
953 |
def check_owned(self, names, shared=-1): |
|
954 |
"""Check if locks are owned in a specific mode. |
|
955 |
|
|
956 |
@type names: sequence or string |
|
957 |
@param names: Lock names (or a single lock name) |
|
958 |
@param shared: See L{SharedLock.is_owned} |
|
959 |
@rtype: bool |
|
960 |
@note: Use L{is_owned} to check if the current thread holds I{any} lock and |
|
961 |
L{list_owned} to get the names of all owned locks |
|
962 |
|
|
963 |
""" |
|
964 |
if isinstance(names, basestring): |
|
965 |
names = [names] |
|
966 |
|
|
967 |
# Avoid check if no locks are owned anyway |
|
968 |
if names and self.is_owned(): |
|
969 |
candidates = [] |
|
970 |
|
|
971 |
# Gather references to all locks (in case they're deleted in the meantime) |
|
972 |
for lname in names: |
|
973 |
try: |
|
974 |
lock = self.__lockdict[lname] |
|
975 |
except KeyError: |
|
976 |
raise errors.LockError("Non-existing lock '%s' in set '%s' (it may" |
|
977 |
" have been removed)" % (lname, self.name)) |
|
978 |
else: |
|
979 |
candidates.append(lock) |
|
980 |
|
|
981 |
return compat.all(lock.is_owned(shared=shared) for lock in candidates) |
|
982 |
else: |
|
983 |
return False |
|
984 |
|
|
949 | 985 |
def _add_owned(self, name=None): |
950 | 986 |
"""Note the current thread owns the given lock""" |
951 | 987 |
if name is None: |
... | ... | |
1512 | 1548 |
""" |
1513 | 1549 |
return self.__keyring[level].list_owned() |
1514 | 1550 |
|
1551 |
def check_owned(self, level, names, shared=-1): |
|
1552 |
"""Check if locks at a certain level are owned in a specific mode. |
|
1553 |
|
|
1554 |
@see: L{LockSet.check_owned} |
|
1555 |
|
|
1556 |
""" |
|
1557 |
return self.__keyring[level].check_owned(names, shared=shared) |
|
1558 |
|
|
1515 | 1559 |
def _upper_owned(self, level): |
1516 | 1560 |
"""Check that we don't own any lock at a level greater than the given one. |
1517 | 1561 |
|
Also available in: Unified diff