Search code examples
pythonmultithreadinglintflake8

Running flake8. Why I'm getting this error. What does threads have to do with it?


Here I'm trying to run flake8 on my project. flake8 myproject But it's giving me

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 576, in _handle_results
    task = get()
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 251, in recv
    return _ForkingPickler.loads(buf.getbuffer())
  File "/home/greenbull/PycharmProjects/QazRiot/venv/lib/python3.8/site-packages/isort/exceptions.py", line 163, in __init__
    self._format_option(name, **option) for name, option in unsupported_settings.items()
AttributeError: 'str' object has no attribute 'items'

Can you help to fix this?


Solution

  • this is two things compounded together:

    • you have isort set up with some unsupported option (you can probably trigger this with isort --help)
    • isort's exceptions are not pickle safe (a bug in isort, please report it there)

    here's a minimal reproduction as to the pickling error:

    >>> from isort.exceptions import UnsupportedSettings
    >>> import pickle
    >>> e = UnsupportedSettings({'foo': {'value': 'bar', 'source': 'wat'}})
    >>> e
    UnsupportedSettings("isort was provided settings that it doesn't support:\n\n\t- foo = bar  (source: 'wat')\n\nFor a complete and up-to-date listing of supported settings see: https://pycqa.github.io/isort/docs/configuration/options.\n")
    >>> pickle.loads(pickle.dumps(e))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/tmp/y/venv/lib/python3.8/site-packages/isort/exceptions.py", line 163, in __init__
        self._format_option(name, **option) for name, option in unsupported_settings.items()
    AttributeError: 'str' object has no attribute 'items'
    

    flake8 uses multiprocessing (and multiprocessing uses pickle to send arguments) for running which is why this is triggered. you can work around this (to at least display the original error message) by running flake8 -j1


    disclaimer: I'm the current flake8 maintainer