本文整理汇总了Python中fcntl.LOCK_UN属性的典型用法代码示例。如果您正苦于以下问题:Python fcntl.LOCK_UN属性的具体用法?Python fcntl.LOCK_UN怎么用?Python fcntl.LOCK_UN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类fcntl
的用法示例。
在下文中一共展示了fcntl.LOCK_UN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: release
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def release(self):
"""Release the lock by deleting `self.lockfile`."""
if not self._lock.is_set():
return False
try:
fcntl.lockf(self._lockfile, fcntl.LOCK_UN)
except IOError: # pragma: no cover
pass
finally:
self._lock.clear()
self._lockfile = None
try:
os.unlink(self.lockfile)
except (IOError, OSError): # pragma: no cover
pass
return True
示例2: __exit__
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
# Flush any buffered data to disk. This is needed to prevent race
# condition which happens from the moment of releasing file lock
# till closing the file.
self._fo.flush()
try:
if sys.platform == 'win32':
self._fo.seek(0)
msvcrt.locking(self._fo.fileno(), msvcrt.LK_UNLCK, 1)
else:
fcntl.flock(self._fo.fileno(), fcntl.LOCK_UN)
finally:
self._fo.close()
return exc_value is None
示例3: unlock_file
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_file(self, name):
f = self.locks.get(name)
if not f:
self.log(DEBUG, "unlock_file: %s not locked", name)
return
# XXXX does this create a possible race condition?
if 0:
try:
os.unlink(name)
except:
pass
status = fcntl.lockf(f, fcntl.LOCK_UN)
f.close()
del self.locks[name]
return status
示例4: udpate_status
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def udpate_status(status_file_path, module_data, module):
lock_file_path = "{}.lock".format(status_file_path)
while True:
status_file_lock = open(lock_file_path, 'r')
try:
fcntl.flock(status_file_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
with open(status_file_path, "r+") as status_file:
data = json.load(status_file)
status_file.seek(0)
data[module].update(module_data)
json.dump(data, status_file)
fcntl.flock(status_file_lock, fcntl.LOCK_UN)
return
except:
time.sleep(0.1)
status_file_lock.close()
示例5: __exit__
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_val, traceback):
if (exc_type is None and self._data_written):
os.replace(self._temp_file_path, self._config_file)
os.chmod(self._config_file, 0o660)
shutil.chown(self._config_file, user=USER, group=GROUP)
else:
self._temp_file.close()
os.unlink(self._temp_file_path)
if (self._Log):
self._Log.error(f'configuration manager exiting with error: {exc_val}')
# releasing lock for purposes specified in flock(1) man page under -u (unlock)
fcntl.flock(self._config_lock, fcntl.LOCK_UN)
self._config_lock.close()
if (self._Log):
self._Log.debug(f'file lock released for {self._file_name}')
if (exc_type is not ValidationError):
return True
#will load json data from file, convert it to a python dict, then returned as object
示例6: do_write
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def do_write(self, obuf):
my_flock = flock
try:
my_flock(self.log, LOCK_EX)
except IOError as e:
# Catch ENOTSUP
if e.args[0] != 45:
raise e
my_flock = lambda x, y: None
try:
self.log.write(obuf)
self.log.flush()
except:
pass
my_flock(self.log, LOCK_UN)
示例7: unlock_and_close
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_and_close(self):
"""Close and unlock the file using the fcntl.lockf primitive."""
if self._locked:
fcntl.lockf(self._fh.fileno(), fcntl.LOCK_UN)
self._locked = False
if self._fh:
self._fh.close()
示例8: release
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def release(self):
fcntl.flock(self.handle, fcntl.LOCK_UN)
示例9: __exit__
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
if self._lock_file:
fcntl.lockf(self._lock_file.fileno(), fcntl.LOCK_UN)
self._lock_file.close()
示例10: lock
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def lock():
# Since Local Mode uses the same port for serving, we need a lock in order
# to allow concurrent test execution.
local_mode_lock_fd = open(LOCK_PATH, 'w')
local_mode_lock = local_mode_lock_fd.fileno()
fcntl.lockf(local_mode_lock, fcntl.LOCK_EX)
try:
yield
finally:
time.sleep(5)
fcntl.lockf(local_mode_lock, fcntl.LOCK_UN)
示例11: unlock
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock(f):
ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
return (ret == 0)
示例12: _unlock_file
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _unlock_file(f):
"""Unlock file f using lockf and dot locking."""
if fcntl:
fcntl.lockf(f, fcntl.LOCK_UN)
if os.path.exists(f.name + '.lock'):
os.remove(f.name + '.lock')
示例13: _release
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _release(self):
# Do not remove the lockfile:
#
# https://github.com/benediktschmitt/py-filelock/issues/31
# https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
fd = self._lock_file_fd
self._lock_file_fd = None
fcntl.flock(fd, fcntl.LOCK_UN)
os.close(fd)
return None
# Soft lock
# ~~~~~~~~~
示例14: read_release
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def read_release(self):
with self.__local.f as f:
self.__local.f = None
lockf(f, LOCK_UN)
示例15: unlock_file
# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_file(lockfile):
fcntl.lockf(lockfile, fcntl.LOCK_UN)
lockfile.close()
# Utility functions for dealing with external processes