本文整理汇总了Python中portalocker.unlock方法的典型用法代码示例。如果您正苦于以下问题:Python portalocker.unlock方法的具体用法?Python portalocker.unlock怎么用?Python portalocker.unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类portalocker
的用法示例。
在下文中一共展示了portalocker.unlock方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def _do_unlock(self):
if self.stream_lock:
if self.is_locked:
unlock(self.stream_lock)
self.is_locked = False
self.stream_lock.close()
self.stream_lock = None
else:
self._console_log("No self.stream_lock to unlock", stack=True)
示例2: unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def unlock(file):
hfile = win32file._get_osfhandle(_getfd(file))
try:
win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
except pywintypes.error, exc_value:
if exc_value[0] == 158:
# error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
# To match the 'posix' implementation, silently ignore this error
pass
else:
# Q: Are there exceptions/codes we should be dealing with here?
raise
示例3: unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def unlock(file):
hfile = msvcrt.get_osfhandle(file.fileno())
overlapped = OVERLAPPED()
UnlockFileEx(hfile, 0, 0, 0xFFFF0000, ctypes.byref(overlapped))
示例4: close
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def close(self):
if self.file is not None:
unlock(self.file)
self.file.close()
self.file = None
示例5: unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def unlock(file):
hfile = win32file._get_osfhandle(file.fileno())
win32file.UnlockFileEx(hfile, 0, 0x7fff0000, __overlapped)
示例6: close
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def close(self):
if not self.file is None:
unlock(self.file)
self.file.close()
self.file = None
示例7: _unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def _unlock(self, response):
if response and response.session_file and response.session_locked:
try:
portalocker.unlock(response.session_file)
response.session_locked = False
except: # this should never happen but happens in Windows
pass
示例8: _open_shelve_and_lock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def _open_shelve_and_lock(self):
"""Open and return a shelf object, obtaining an exclusive lock
on self.locker first. Replaces the close method of the
returned shelf instance with one that releases the lock upon
closing."""
storage = None
locker = None
locked = False
try:
locker = locker = open(self.locker_name, 'a')
portalocker.lock(locker, portalocker.LOCK_EX)
locked = True
try:
storage = shelve.open(self.shelve_name)
except:
logger.error('corrupted cache file %s, will try rebuild it'
% self.shelve_name)
storage = None
if storage is None:
if os.path.exists(self.shelve_name):
os.unlink(self.shelve_name)
storage = shelve.open(self.shelve_name)
if not CacheAbstract.cache_stats_name in storage.keys():
storage[CacheAbstract.cache_stats_name] = {
'hit_total': 0, 'misses': 0}
storage.sync()
except Exception, e:
if storage:
storage.close()
storage = None
if locked:
portalocker.unlock(locker)
locker.close()
locked = False
raise RuntimeError(
'unable to create/re-create cache file %s' % self.shelve_name)
示例9: release
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def release(self):
"""
this function writes into cron.master the time when cron job
was completed
"""
if not self.master.closed:
portalocker.lock(self.master, portalocker.LOCK_EX)
logger.debug('WEB2PY CRON: Releasing cron lock')
self.master.seek(0)
(start, stop) = cPickle.load(self.master)
if start == self.now: # if this is my lock
self.master.seek(0)
cPickle.dump((self.now, time.time()), self.master)
portalocker.unlock(self.master)
self.master.close()
示例10: unlock
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def unlock(file):
hfile = win32file._get_osfhandle(file.fileno())
try:
win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
except pywintypes.error, exc_value:
if exc_value[0] == 158:
# error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
# To match the 'posix' implementation, silently ignore this error
pass
else:
# Q: Are there exceptions/codes we should be dealing with here?
raise
示例11: acquire
# 需要导入模块: import portalocker [as 别名]
# 或者: from portalocker import unlock [as 别名]
def acquire(self, startup=False):
"""
returns the time when the lock is acquired or
None if cron already running
lock is implemented by writing a pickle (start, stop) in cron.master
start is time when cron job starts and stop is time when cron completed
stop == 0 if job started but did not yet complete
if a cron job started within less than 60 seconds, acquire returns None
if a cron job started before 60 seconds and did not stop,
a warning is issue "Stale cron.master detected"
"""
if sys.platform == 'win32':
locktime = 59.5
else:
locktime = 59.99
if portalocker.LOCK_EX is None:
logger.warning('WEB2PY CRON: Disabled because no file locking')
return None
self.master = open(self.path, 'rb+')
try:
ret = None
portalocker.lock(self.master, portalocker.LOCK_EX)
try:
(start, stop) = cPickle.load(self.master)
except:
(start, stop) = (0, 1)
if startup or self.now - start > locktime:
ret = self.now
if not stop:
# this happens if previous cron job longer than 1 minute
logger.warning('WEB2PY CRON: Stale cron.master detected')
logger.debug('WEB2PY CRON: Acquiring lock')
self.master.seek(0)
cPickle.dump((self.now, 0), self.master)
self.master.flush()
finally:
portalocker.unlock(self.master)
if not ret:
# do this so no need to release
self.master.close()
return ret