Skip to content

import six.moves.http_client locks interpreter #261

@pelson

Description

@pelson

When importing six.moves.http_client within a script my interpreter freezes up. I don't get the same behaviour when importing in the REPL:

$ python       
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51) 
[GCC 7.2.0] on linux
...
>>> import six.moves.http_client
>>> 
$ cat foo.py
import six
print('Six version: ', six.__version__)
import six.moves.http_client
print('six.moves.http_client')

$ python foo.py
Six version:  1.11.0
...
<wait a very long time and then KeyboardInterrupt to get some traceback>
...
^CTraceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo.sh", line 3, in <module>
    import six.moves.http_client
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
  File "<frozen importlib._bootstrap>", line 867, in _find_spec_legacy
  File "<frozen importlib._bootstrap>", line 449, in spec_from_loader
  File "lib/python3.6/site-packages/six.py", line 216, in is_package
    return hasattr(self.__get_module(fullname), "__path__")
  File "lib/python3.6/site-packages/six.py", line 118, in __getattr__
    _module = self._resolve()
  File "lib/python3.6/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "lib/python3.6/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "<frozen importlib._bootstrap>", line 202, in _lock_unlock_module
  File "<frozen importlib._bootstrap>", line 98, in acquire
KeyboardInterrupt

Changing the import to from six.moves import http_client results in the import working fine. I'm on a RHEL6 machine, but using the Anaconda distribution (hence the modern GCC compiler). I tried the same on my mac and couldn't reproduce the issue.

This might seem esoteric, but I've traced this back from urllib3 which itself I traced from requests. The line that makes this import call is in urllibr3.exceptions. I'll submit a PR against urllib3 for this, but wanted to raise this here - I guess it is not expected behaviour, and worth sharing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions