Repository: spotify/luigi
File: luigi/rpc.py (Python)

Code before:
    """
    Scheduler proxy object. Talks to a RemoteSchedulerResponder.
    """

    def __init__(self, url='http://localhost:8082/', connect_timeout=None):
        assert not url.startswith('http+unix://') or HAS_UNIX_SOCKET, (
            'You need to install requests-unixsocket for Unix socket support.'
        )

        self._url = url.rstrip('/')
        config = configuration.get_config()

        if connect_timeout is None:
            connect_timeout = config.getfloat('core', 'rpc-connect-timeout', 10.0)
        self._connect_timeout = connect_timeout

        self._rpc_retry_attemps = config.getint('core', 'rpc-retry-attempts', 3)
        self._rpc_retry_wait = config.getint('core', 'rpc-retry-wait', 30)

        if HAS_REQUESTS:
            self._fetcher = RequestsFetcher(requests.Session())
        else:
            self._fetcher = URLLibFetcher()

    def _wait(self):
        logger.info("Wait for %d seconds" % self._rpc_retry_wait)
        time.sleep(self._rpc_retry_wait)

    def _fetch(self, url_suffix, body, log_exceptions=True):
        full_url = _urljoin(self._url, url_suffix)
        last_exception = None
        attempt = 0
        while attempt < self._rpc_retry_attemps:
            attempt += 1
            if last_exception:
                logger.info("Retrying %r/%r" %(attempt, self._rpc_retry_attemps))
                self._wait()  # wait for a bit and retry
            try:
                response = self._fetcher.fetch(full_url, body, self._connect_timeout)
                break
            except self._fetcher.raises as e:
                last_exception = e
                if log_exceptions:
                    logger.exception("Failed connecting to remote scheduler %r", self._url)
                continue
        else:
            raise RPCError(
                "Errors (%d attempts) when connecting to remote scheduler %r" %
                (self._rpc_retry_attemps, self._url),
                last_exception
            )

Review comment (suggestion):
Does this line really work, I thought you should replace ` %` with `,`.

Code after:
    """
    Scheduler proxy object. Talks to a RemoteSchedulerResponder.
    """

    def __init__(self, url='http://localhost:8082/', connect_timeout=None):
        assert not url.startswith('http+unix://') or HAS_UNIX_SOCKET, (
            'You need to install requests-unixsocket for Unix socket support.'
        )

        self._url = url.rstrip('/')
        config = configuration.get_config()

        if connect_timeout is None:
            connect_timeout = config.getfloat('core', 'rpc-connect-timeout', 10.0)
        self._connect_timeout = connect_timeout

        self._rpc_retry_attempts = config.getint('core', 'rpc-retry-attempts', 3)
        self._rpc_retry_wait = config.getint('core', 'rpc-retry-wait', 30)

        if HAS_REQUESTS:
            self._fetcher = RequestsFetcher(requests.Session())
        else:
            self._fetcher = URLLibFetcher()

    def _wait(self):
        logger.info("Wait for %d seconds" % self._rpc_retry_wait)
        time.sleep(self._rpc_retry_wait)

    def _fetch(self, url_suffix, body, log_exceptions=True):
        full_url = _urljoin(self._url, url_suffix)
        last_exception = None
        attempt = 0
        while attempt < self._rpc_retry_attempts:
            attempt += 1
            if last_exception:
                logger.info("Retrying attempt %r of %r (max)" % (attempt, self._rpc_retry_attempts))
                self._wait()  # wait for a bit and retry
            try:
                response = self._fetcher.fetch(full_url, body, self._connect_timeout)
                break
            except self._fetcher.raises as e:
                last_exception = e
                if log_exceptions:
                    logger.exception("Failed connecting to remote scheduler %r", self._url)
                continue
        else:
            raise RPCError(
                "Errors (%d attempts) when connecting to remote scheduler %r" %
                (self._rpc_retry_attempts, self._url),
                last_exception
            )