本文整理汇总了Python中lock.Lock.acquire方法的典型用法代码示例。如果您正苦于以下问题:Python Lock.acquire方法的具体用法?Python Lock.acquire怎么用?Python Lock.acquire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lock.Lock
的用法示例。
在下文中一共展示了Lock.acquire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: daemonize
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def daemonize(args, callback):
with DaemonContext():
from touchandgo.logger import log_set_up
log_set_up(True)
log = logging.getLogger('touchandgo.daemon')
log.info("running daemon")
create_process = False
lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
args.sea_ep[1], args.port)
if lock.is_locked():
log.debug("lock active")
lock_pid = lock.get_pid()
if not lock.is_same_file(args.name, args.sea_ep[0],
args.sea_ep[1]) \
or not is_process_running(lock_pid):
try:
log.debug("killing process %s" % lock_pid)
os.kill(lock_pid, signal.SIGQUIT)
except OSError:
pass
except TypeError:
pass
lock.break_lock()
create_process = True
else:
create_process = True
if create_process:
log.debug("creating proccess")
lock.acquire()
callback()
lock.release()
else:
log.debug("same daemon process")
示例2: detachThin
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def detachThin(session, lvmCache, srUuid, vdiUuid):
"""Shrink the VDI to the minimal size if no one is using it"""
lvName = LV_PREFIX[VDI_TYPE_VHD] + vdiUuid
path = os.path.join(VG_LOCATION, VG_PREFIX + srUuid, lvName)
lock = Lock(vhdutil.LOCK_TYPE_SR, srUuid)
lock.acquire()
vdiRef = session.xenapi.VDI.get_by_uuid(vdiUuid)
vbds = session.xenapi.VBD.get_all_records_where( \
"field \"VDI\" = \"%s\"" % vdiRef)
numPlugged = 0
for vbdRec in vbds.values():
if vbdRec["currently_attached"]:
numPlugged += 1
if numPlugged > 1:
raise util.SMException("%s still in use by %d others" % \
(vdiUuid, numPlugged - 1))
lvmCache.activate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
try:
newSize = calcSizeLV(vhdutil.getSizePhys(path))
deflate(lvmCache, lvName, newSize)
finally:
lvmCache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
lock.release()
示例3: PhysicalView
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
class PhysicalView(Base):
def __init__(self, dfs):
Base.__init__(self, dfs)
self.lock_ = Lock(dfs)
self.createBaseFolder()
def read(self, fileName, buf, offset, bufsize):
# TODO add thread safetly
filePath = os.path.join(self.getBasePath(), fileName)
size = self.getFileSize(fileName)
if offset + bufsize > size:
self.log_.w('tried to read ' + fileName + ' but size is ' + str(size) +
' and bufsize + offset = ' + str(offset + bufsize))
return err.InvalidBufferSize
self.lock_.acquire()
try:
f = open(filePath, "r")
except Exception, ex:
self.log_.e('error opening file in read mode ' + filePath + ': ' + str(ex))
self.lock_.release()
return err.FileNotFound
status = err.OK
f.seek(offset)
try:
data = f.read(bufsize)
for i, d in enumerate(data):
buf[i] = d
except Exception, ex:
self.log_.e('failed to read ' + filePath + ' from ' + str(offset) + ' to ' + str(offset + bufsize) + ': ' + str(ex))
status = err.CannotReadFile
示例4: daemonize
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def daemonize(args, callback):
with DaemonContext():
create_process = False
lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
args.sea_ep[1], args.port)
if lock.is_locked():
lock_pid = lock.get_pid()
if not lock.is_same_file(args.name, args.sea_ep[0],
args.sea_ep[1]) \
or not is_process_running(lock_pid):
try:
os.kill(lock_pid, signal.SIGQUIT)
except OSError:
pass
except TypeError:
pass
lock.break_lock()
create_process = True
else:
create_process = True
if create_process:
lock.acquire()
callback(args.name, season=args.sea_ep[0], episode=args.sea_ep[1],
serve=True, port=args.port)
lock.release()
示例5: checkLocked
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def checkLocked(obj, ns):
"""Lock-protected access"""
lock = Lock(obj, ns)
lock.acquire()
try:
return RefCounter.check(obj, ns)
finally:
lock.release()
示例6: setReadonly
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def setReadonly(self, lvName, readonly):
path = self._getPath(lvName)
if self.lvs[lvName].readonly != readonly:
uuids = util.findall_uuid(path)
ns = lvhdutil.NS_PREFIX_LVM + uuids[0]
lock = Lock(uuids[1], ns)
lock.acquire()
lvutil.setReadonly(path, readonly)
lock.release()
self.lvs[lvName].readonly = readonly
示例7: setReadonly
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def setReadonly(self, lvName, readonly):
path = self._getPath(lvName)
if self.lvs[lvName].readonly != readonly:
uuids = util.findall_uuid(path)
ns = lvhdutil.NS_PREFIX_LVM + uuids[0]
# Taking this lock is needed to avoid a race condition
# with tap-ctl open (which is now taking the same lock)
lock = Lock("lvchange-p", ns)
lock.acquire()
lvutil.setReadonly(path, readonly)
lock.release()
self.lvs[lvName].readonly = readonly
示例8: activate
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def activate(self, ns, ref, lvName, binary):
lock = Lock(ref, ns)
lock.acquire()
try:
count = RefCounter.get(ref, binary, ns)
if count == 1:
try:
self.activateNoRefcount(lvName)
except util.CommandException:
RefCounter.put(ref, binary, ns)
raise
finally:
lock.release()
示例9: _cbt_op
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def _cbt_op(self, uuid, func, *args):
# Lock cbtlog operations
from lock import Lock
lock = Lock("cbtlog", str(uuid))
lock.acquire()
try:
logname = self._get_cbt_logname(uuid)
activated = self._activate_cbt_log(logname)
ret = func(*args)
if activated:
self._deactivate_cbt_log(logname)
return ret
finally:
lock.release()
示例10: deactivate
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def deactivate(self, sr_uuid, vdi_uuid):
"""Deactivate VDI - called post tapdisk close"""
if self._get_blocktracking_status():
from lock import Lock
lock = Lock("cbtlog", str(vdi_uuid))
lock.acquire()
try:
logpath = self._get_cbt_logpath(vdi_uuid)
logname = self._get_cbt_logname(vdi_uuid)
self._cbt_op(vdi_uuid, cbtutil.set_cbt_consistency, logpath, True)
# Finally deactivate log file
self._deactivate_cbt_log(logname)
finally:
lock.release()
示例11: deactivateVdi
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def deactivateVdi(sr_uuid, vdi_uuid, vhd_path):
name_space = lvhdutil.NS_PREFIX_LVM + sr_uuid
lock = Lock(vdi_uuid, name_space)
lock.acquire()
try:
count = RefCounter.put(vdi_uuid, False, name_space)
if count > 0:
return
try:
lvutil.deactivateNoRefcount(vhd_path)
except Exception, e:
util.SMlog(" lv de-activate failed for %s with error %s" %
(vhd_path, str(e)))
RefCounter.get(vdi_uuid, False, name_space)
finally:
lock.release()
示例12: LogicalView
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
class LogicalView(Base):
def __init__(self, dfs):
Base.__init__(self, dfs)
self.lock_ = Lock(dfs)
self.fileList_ = {}
def beginLocalUpdate(self, fileName):
file = self.getFile(fileName)
if file.latestVersion != file.localVersion:
file.localVersion = file.latestVersion.copy()
file.ownNoChunks()
def add(self, fileName, fileSize):
self.lock_.acquire()
f = File(fileName, 1, fileSize, self.dfs_.id.str)
self.fileList_[fileName] = f
self.lock_.release()
def delete(self, fileName):
self.lock_.acquire()
self.fileList_[fileName].isDeleted = True
self.lock_.release()
def exists(self, fileName):
return (fileName in self.fileList_)
def getLocalVersion(self, fileName):
return self.fileList_[fileName].getLocalVersion()
def getLatestVersion(self, fileName):
return self.fileList_[fileName].getLatestVersion()
def setNewVersion(self, fileName, version):
self.fileList_[fileName].setNewVersion(version.copy())
def setLocalVersion(self, fileName, numEdits, fileSize, lastEdited):
self.fileList_[fileName].setLocalVersion(numEdits, fileSize, lastEdited)
def getFileList(self):
return self.fileList_.values()
def getState(self):
return self.fileList_
def getFile(self, fileName):
return self.fileList_[fileName]
示例13: attachThin
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def attachThin(journaler, srUuid, vdiUuid):
"""Ensure that the VDI LV is expanded to the fully-allocated size"""
lvName = LV_PREFIX[VDI_TYPE_VHD] + vdiUuid
vgName = VG_PREFIX + srUuid
lock = Lock(vhdutil.LOCK_TYPE_SR, srUuid)
lvmCache = journaler.lvmCache
lock.acquire()
vhdInfo = vhdutil.getVHDInfoLVM(lvName, extractUuid, vgName)
newSize = calcSizeVHDLV(vhdInfo.sizeVirt)
currSizeLV = lvmCache.getSize(lvName)
if newSize <= currSizeLV:
return
lvmCache.activate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
try:
inflate(journaler, srUuid, vdiUuid, newSize)
finally:
lvmCache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
lock.release()
示例14: deactivate
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def deactivate(self, ns, ref, lvName, binary):
lock = Lock(ref, ns)
lock.acquire()
try:
count = RefCounter.put(ref, binary, ns)
if count > 0:
return
refreshed = False
while True:
lvInfo = self.getLVInfo(lvName)
if len(lvInfo) != 1:
raise util.SMException("LV info not found for %s" % ref)
info = lvInfo[lvName]
if info.open:
if refreshed:
# should never happen in normal conditions but in some
# failure cases the recovery code may not be able to
# determine what the correct refcount should be, so it
# is not unthinkable that the value might be out of
# sync
util.SMlog("WARNING: deactivate: LV %s open" % lvName)
return
# check again in case the cached value is stale
self.refresh()
refreshed = True
else:
break
try:
self.deactivateNoRefcount(lvName)
except util.CommandException:
self.refresh()
if self.getLVInfo(lvName):
util.SMlog("LV %s could not be deactivated" % lvName)
if lvInfo[lvName].active:
util.SMlog("Reverting the refcount change")
RefCounter.get(ref, binary, ns)
raise
else:
util.SMlog("LV %s not found" % lvName)
finally:
lock.release()
示例15: activate
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import acquire [as 别名]
def activate(self, sr_uuid, vdi_uuid):
"""Activate VDI - called pre tapdisk open"""
if self._get_blocktracking_status():
if self.sr.srcmd.params.has_key('args'):
read_write = self.sr.srcmd.params['args'][0]
if read_write == "false":
# Disk is being attached in RO mode,
# don't attach metadata log file
return None
from lock import Lock
lock = Lock("cbtlog", str(vdi_uuid))
lock.acquire()
try:
logpath = self._get_cbt_logpath(vdi_uuid)
logname = self._get_cbt_logname(vdi_uuid)
# Activate CBT log file, if required
self._activate_cbt_log(logname)
finally:
lock.release()
# Check and update consistency
consistent = self._cbt_op(vdi_uuid, cbtutil.get_cbt_consistency,
logpath)
if not consistent:
alert_name = "VDI_CBT_METADATA_INCONSISTENT"
alert_str = ("Changed Block Tracking metadata is inconsistent"
" for disk %s." % vdi_uuid)
self._disable_cbt_on_error(alert_name, alert_str)
return None
self._cbt_op(self.uuid, cbtutil.set_cbt_consistency,
logpath, False)
return {'cbtlog': logpath}
return None