Skip to content

dask/bytes/tests/test_http.py tries to run the python2 interpreter on Debian #3449

Closed

Description

@detrout

Hello

I was updating the Dask packaging for Debian to Dask 0.17.2 and had test failures during the build in dask/bytes/tests/test_httpy.

E           requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8999): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8be024b160>: Failed to establish a new connection: [Errno 111] Connection refused',))

/usr/lib/python3/dist-packages/requests/adapters.py:508: ConnectionError

During handling of the above exception, another exception occurred:

    @pytest.fixture(scope='module')
    def dir_server():
        with tmpdir() as d:
            for fn in files:
                with open(os.path.join(d, fn), 'wb') as f:
                    f.write(b'a' * 10000)
    
            if PY2:
                cmd = ['python', '-m', 'SimpleHTTPServer', '8999']
            else:
                cmd = ['python', '-m', 'http.server', '8999']
            p = subprocess.Popen(cmd, cwd=d)
            timeout = 10
            while True:
                try:
                    requests.get('http://localhost:8999')
                    break
                except requests.exceptions.ConnectionError:
                    time.sleep(0.1)
                    timeout -= 0.1
                    if timeout < 0:
>                       raise RuntimeError('Server did not appear')
E                       RuntimeError: Server did not appear

dask/bytes/tests/test_http.py:36: RuntimeError

I'm only building a Python 3 version, and I realized this piece of code in dir_server test_http.py was going to run the wrong version of Python.

      if PY2:
            cmd = ['python', '-m', 'SimpleHTTPServer', '8999']
        else:
            cmd = ['python', '-m', 'http.server', '8999']

On Debian (and I believe other Linux systems) the system Python 3 interpreter is installed as
/usr/bin/python3, and /usr/bin/python is the Python 2 interpreter.

So because the test is running under Python 3 it uses the Python 3 arguments, but launches the default Python 2 interpreter.

I think it works for you because you're doing most of your testing in conda or a virtualenv where the first python on the path is the expected python version.

My idea to solve the problem robustly is to replace 'python' with sys.executable, which should guarantee that the test HTTP server is running under the same python that the tests are using regardless of the test environment.

I have a pull request, but I thought I should file the issue before making the pull request.

Activity

  1. detrout commented on Apr 29, 2018

    @detrout
    ContributorAuthor

    Sigh I reran all the tests in a new environment with my patch... and now I have a new exeception.

    dir_server = '/tmp/tmpuy23zxon'
    
        def test_files(dir_server):
            root = 'http://localhost:8999/'
            fs = open_files([root + f for f in files])
            for f, f2 in zip(fs, files):
    >           with f as f:
    
    dask/bytes/tests/test_http.py:110: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    dask/bytes/core.py:166: in __enter__
        f = SeekableFile(self.fs.open(self.path, mode=mode))
    dask/bytes/http.py:55: in open
        return HTTPFile(url, self.session, block_size, **self.kwargs)
    dask/bytes/http.py:101: in __init__
        **self.kwargs)
    dask/bytes/http.py:279: in file_size
        r.raise_for_status()
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    self = <Response [403]>
    
        def raise_for_status(self):
            """Raises stored :class:`HTTPError`, if one occurred."""
        
            http_error_msg = ''
            if isinstance(self.reason, bytes):
                # We attempt to decode utf-8 first because some servers
                # choose to localize their reason strings. If the string
                # isn't utf-8, we fall back to iso-8859-1 for all other
                # encodings. (See PR #3538)
                try:
                    reason = self.reason.decode('utf-8')
                except UnicodeDecodeError:
                    reason = self.reason.decode('iso-8859-1')
            else:
                reason = self.reason
        
            if 400 <= self.status_code < 500:
                http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)
        
            elif 500 <= self.status_code < 600:
                http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)
        
            if http_error_msg:
    >           raise HTTPError(http_error_msg, response=self)
    E           requests.exceptions.HTTPError: 403 Client Error: Forbidden file type or location for url: http://localhost:8999/a
    
    /usr/lib/python3/dist-packages/requests/models.py:935: HTTPError
    

    Here's the commit, but apparently I need to keep investigating.
    detrout@481c339

  2. mrocklin commented on Apr 29, 2018

    @mrocklin
    Member

    I agree that using sys.executable is preferable and a PR would be welcome.

    At first glance the exception doesn't mean much to me. @martindurant may have more experience here though.

  3. mrocklin commented on Apr 29, 2018

    @mrocklin
    Member

    As always @detrout thank you for keeping the project up-to-date on Debian. I appreciate it.

  4. martindurant commented on Apr 29, 2018

    @martindurant
    Member

    403 forbidden?
    The server is a simple http server without access controls, so that seems quite weird. It should start a process to serve files from a temp directory created in the main process - might the temp directory be accessible only to the process that made it?

  5. mrocklin commented on Apr 29, 2018

    @mrocklin
    Member

    @detrout I wonder if replacing localhost with 127.0.0.1 would work for you? Sometimes different machines treat localhost differently.

  6. detrout commented on Apr 30, 2018

    @detrout
    ContributorAuthor

    It looks like I was tired and my test environment wasn't clean enough and the some of the unpatched code was still around. I cleaned, and rebuilt and the tests (for dask) all pass now. (There's still some problems with distributed, but I don't have a good handle on it yet)

  7. mrocklin commented on Apr 30, 2018

    @mrocklin
    Member
  8. detrout commented on May 1, 2018

    @detrout
    ContributorAuthor

    I think this is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions