本文整理汇总了Python中msvcrt.LK_UNLCK属性的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.LK_UNLCK属性的具体用法?Python msvcrt.LK_UNLCK怎么用?Python msvcrt.LK_UNLCK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类msvcrt
的用法示例。
在下文中一共展示了msvcrt.LK_UNLCK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __exit__
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [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
示例2: _release
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _release(self):
fd = self._lock_file_fd
self._lock_file_fd = None
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
os.close(fd)
try:
os.remove(self._lock_file)
# Probably another instance of the application
# that acquired the file lock.
except OSError:
pass
return None
# Unix locking mechanism
# ~~~~~~~~~~~~~~~~~~~~~~
示例3: _release
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _release(self):
fd = self._lock_file_fd
self._lock_file_fd = None
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
os.close(fd)
try:
os.remove(self._lock_file)
# Probably another instance of the application
# that acquired the file lock.
except OSError:
pass
return None
# Unix locking mechanism
# ~~~~~~~~~~~~~~~~~~~~~~
示例4: _release
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _release(self):
fd = self._lock_file_fd
self._lock_file_fd = None
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
try:
os.close(fd)
except:
fd.close()
try:
os.remove(self._lock_file)
# Probably another instance of the application
# that acquired the file lock.
except OSError:
pass
return None
# Unix locking mechanism
# ~~~~~~~~~~~~~~~~~~~~~~
示例5: _unlock
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _unlock(lockfile):
fileno = lockfile.fileno()
msvcrt.locking(fileno, msvcrt.LK_UNLCK, 1)
示例6: unlock
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def unlock(self, length, start=0, whence=0):
"""Posix compatible unlock."""
orig = self.tell()
self.seek(start, whence)
try:
msvcrt.locking(self.fileno(), msvcrt.LK_UNLCK, length)
finally:
self.seek(orig)
示例7: _unlock_file
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _unlock_file(self, name, f):
if name == self.path:
size = self.size
else:
size = self.tops[name]
import msvcrt
for p in range(0, min(size, MAXLOCKRANGE), MAXLOCKSIZE):
f.seek(p)
msvcrt.locking(f.fileno(), msvcrt.LK_UNLCK, min(MAXLOCKSIZE, size - p))
示例8: _unlock_file
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _unlock_file(self, name, f):
import msvcrt
for p in range(0, min(self.sizes[name], MAXLOCKRANGE), MAXLOCKSIZE):
f.seek(p)
msvcrt.locking(f.fileno(), msvcrt.LK_UNLCK, min(MAXLOCKSIZE, self.sizes[name] - p))
示例9: release
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def release(self):
msvcrt.locking(self.handle.fileno(), msvcrt.LK_UNLCK, 1)
示例10: unlock
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def unlock(file_):
try:
savepos = file_.tell()
if savepos:
file_.seek(0)
try:
msvcrt.locking(file_.fileno(), msvcrt.LK_UNLCK, 1)
except IOError as e:
raise SensorsAnalyticsFileLockException(e)
finally:
if savepos:
file_.seek(savepos)
except IOError as e:
raise SensorsAnalyticsFileLockException(e)
示例11: release
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def release(self):
msvcrt.locking(self._fd, msvcrt.LK_UNLCK, 1)
self._lock.release()
示例12: _locked
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _locked(
fileno: int,
blocked_cb: Callable[[], None],
) -> Generator[None, None, None]:
try:
# TODO: https://github.com/python/typeshed/pull/3607
msvcrt.locking(fileno, msvcrt.LK_NBLCK, _region) # type: ignore
except OSError:
blocked_cb()
while True:
try:
# TODO: https://github.com/python/typeshed/pull/3607
msvcrt.locking(fileno, msvcrt.LK_LOCK, _region) # type: ignore # noqa: E501
except OSError as e:
# Locking violation. Returned when the _LK_LOCK or _LK_RLCK
# flag is specified and the file cannot be locked after 10
# attempts.
if e.errno != errno.EDEADLOCK:
raise
else:
break
try:
yield
finally:
# From cursory testing, it seems to get unlocked when the file is
# closed so this may not be necessary.
# The documentation however states:
# "Regions should be locked only briefly and should be unlocked
# before closing a file or exiting the program."
# TODO: https://github.com/python/typeshed/pull/3607
msvcrt.locking(fileno, msvcrt.LK_UNLCK, _region) # type: ignore
示例13: _unlock_file
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _unlock_file(self):
try:
self.fp.seek(0)
msvcrt.locking(self.fp.fileno(), msvcrt.LK_UNLCK, 1)
except IOError:
raise UnlockError(self.fp.name)
示例14: _unlock_file
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def _unlock_file(file):
try:
file.seek(0)
msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 1)
except OSError as e:
raise LockError(
"Couldn't unlock {0}, errno is {1}".format(file.name, e.errno)
)
示例15: unlock_file
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_UNLCK [as 别名]
def unlock_file(handle):
if sys.platform == 'win32':
msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
else:
fcntl.flock(handle, fcntl.LOCK_UN)