Пример #1
0
    def _capture_port_no_lock(self, port, sock_type):
        if port in self._filelocks:
            return False

        filelock = None
        if self._sync_dir:
            # yatest.common should try to be hermetic and don't have peerdirs
            # otherwise, PYTEST_SCRIPT (aka USE_ARCADIA_PYTHON=no) won't work
            import library.python.filelock

            filelock = library.python.filelock.FileLock(os.path.join(self._sync_dir, str(port)))
            if not filelock.acquire(blocking=False):
                return False
            if self.is_port_free(port, sock_type):
                self._filelocks[port] = filelock
                return True
            else:
                filelock.release()
                return False

        if self.is_port_free(port, sock_type):
            self._filelocks[port] = filelock
            return True
        if filelock:
            filelock.release()
        return False
Пример #2
0
    def _capture_port_no_lock(self, port, sock_type):
        if port in self._filelocks:
            return False

        sock = socket.socket(socket.AF_INET6, sock_type)
        try:
            sock.bind(('::', port))
        except socket.error as e:
            if e.errno == errno.EADDRINUSE:
                return False
        finally:
            sock.close()

        if self._sync_dir:
            # yatest.common should try do be hermetic and don't have peerdirs
            # otherwise, PYTEST_SCRIPT (aka USE_ARCADIA_PYTHON=no) won't work
            import library.python.filelock

            filelock = library.python.filelock.FileLock(
                os.path.join(self._sync_dir, str(port)))
            if not filelock.acquire(blocking=False):
                return False
            self._filelocks[port] = filelock
        else:
            # Remember given port without lock
            self._filelocks[port] = None
        return True
Пример #3
0
    def _lock_port(self, port):
        with self._lock:
            if port in self._filelocks:
                return False

            if self._sync_dir:
                # yatest.common should try do be hermetic and don't have peerdirs
                # otherwise, PYTEST_SCRIPT (aka USE_ARCADIA_PYTHON=no) won't work
                import library.python.filelock

                filelock = library.python.filelock.FileLock(
                    os.path.join(self._sync_dir, str(port)))
                if not filelock.acquire(blocking=False):
                    return False
                self._filelocks[port] = filelock
            else:
                # Remember given port without lock
                self._filelocks[port] = None
            return True