Python msvcrt.LK_UNLCK Examples

The following are 21 code examples of msvcrt.LK_UNLCK(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module msvcrt , or try the search function .
Example #1
Source File: filelock.py    From a4kScrapers with MIT License 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #2
Source File: filelock.py    From py-filelock with The Unlicense 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #3
Source File: filelock.py    From plugin.git.browser with GNU General Public License v3.0 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #4
Source File: filelock.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #5
Source File: filelock.py    From Jacinle with MIT License 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #6
Source File: filelock.py    From veros with MIT License 6 votes vote down vote up
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
# ~~~~~~~~~~~~~~~~~~~~~~ 
Example #7
Source File: gtest_parallel.py    From gtest-parallel with Apache License 2.0 6 votes vote down vote up
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 
Example #8
Source File: Storage.py    From p2ptv-pi with MIT License 5 votes vote down vote up
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)) 
Example #9
Source File: Storage.py    From p2ptv-pi with MIT License 5 votes vote down vote up
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)) 
Example #10
Source File: extractRatios.py    From sec-xbrl with Apache License 2.0 5 votes vote down vote up
def release(self):
			msvcrt.locking(self.handle.fileno(), msvcrt.LK_UNLCK, 1) 
Example #11
Source File: sdk.py    From sa-sdk-python with Apache License 2.0 5 votes vote down vote up
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) 
Example #12
Source File: lock.py    From py-solc-x with MIT License 5 votes vote down vote up
def release(self):
        msvcrt.locking(self._fd, msvcrt.LK_UNLCK, 1)
        self._lock.release() 
Example #13
Source File: file_lock.py    From pre-commit with MIT License 5 votes vote down vote up
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 
Example #14
Source File: WindowsServer.py    From pycopia with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: lockfile.py    From opsbro with MIT License 5 votes vote down vote up
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) 
Example #16
Source File: process_lock.py    From fasteners with Apache License 2.0 5 votes vote down vote up
def _unlock(lockfile):
        fileno = lockfile.fileno()
        msvcrt.locking(fileno, msvcrt.LK_UNLCK, 1) 
Example #17
Source File: glock.py    From ReynirPackage with GNU General Public License v3.0 5 votes vote down vote up
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)
                ) 
Example #18
Source File: test_lockutils.py    From oslo.concurrency with Apache License 2.0 5 votes vote down vote up
def unlock_file(handle):
    if sys.platform == 'win32':
        msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
    else:
        fcntl.flock(handle, fcntl.LOCK_UN) 
Example #19
Source File: exfile.py    From CUP with Apache License 2.0 5 votes vote down vote up
def win_unlockfile(fobj):
        """win unlock file"""
        msvcrt.locking(fobj.fileno(), msvcrt.LK_UNLCK, file_size(fobj)) 
Example #20
Source File: lockfile.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #21
Source File: __init__.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def _unlock_file(file):
            try:
                file.seek(0)
                msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 1)
            except IOError:
                raise LockError("Couldn't unlock %r" % file.name)