microsoft / vscode-isort

Import sorting for python using the isort library.
https://marketplace.visualstudio.com/items?itemName=ms-python.isort
MIT License
87 stars 21 forks source link

High RAM usage in WSL2 #88

Closed fwindolf closed 2 years ago

fwindolf commented 2 years ago

I am using VSCode and the isort extension v2022.2.0 (isort=5.10.1)

My pyproject.toml contains:

[tool.isort]
profile = "black"
line_length = 88
multi_line_output = 3
include_trailing_comma = true
skip_gitignore = true
skip = ["notebooks", "resources", "data"]
known_third_party = ["wandb", "hydra"]

I get really high RAM usage for the format_server.py. I tried increasing the WSL2 memory, but after a while the isort format server allocates all free memory on my ubuntu subsystem, until the swap is full and my wsl freezes.

image

The logs contain

Formatter Name: isort
Formatter Module: isort
CWD Format Server: /home/flo/dev/redacted
sys.path used to run Formatter:
    /home/flo/.vscode-server/extensions/ms-python.isort-2022.2.0/bundled/formatter
    /usr/lib/python39.zip
    /usr/lib/python3.9
    /usr/lib/python3.9/lib-dynload
    /home/flo/dev/redacted/.venv/lib/python3.9/site-packages
    /home/flo/dev/redacted
    /home/flo/.vscode-server/extensions/ms-python.isort-2022.2.0/bundled/libs

Settings used to run Formatter:
[
    {
        "workspace": "file:///home/flo/dev/redacted",
        "trace": "error",
        "args": [],
        "severity": {},
        "path": [],
        "interpreter": [
            "/home/flo/dev/redacted/.venv/bin/python"
        ]
    }
]

I get a few exceptions based on #isort: skip_file comments:

Traceback (most recent call last):
  File "/home/flo/.vscode-server/extensions/ms-python.isort-2022.2.0/bundled/formatter/format_server.py", line 143, in _run
    result = utils.run_module(
  File "/home/flo/.vscode-server/extensions/ms-python.isort-2022.2.0/bundled/formatter/utils.py", line 177, in run_module
    return _run_module(module, argv, use_stdin, source)
  File "/home/flo/.vscode-server/extensions/ms-python.isort-2022.2.0/bundled/formatter/utils.py", line 162, in _run_module
    runpy.run_module(module, run_name="__main__")
  File "/usr/lib/python3.9/runpy.py", line 213, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/flo/dev/redacted/.venv/lib/python3.9/site-packages/isort/__main__.py", line 3, in <module>
    main()
  File "/home/flo/dev/redacted/.venv/lib/python3.9/site-packages/isort/main.py", line 1119, in main
    incorrectly_sorted = not api.check_stream(
  File "/home/flo/dev/redacted/.venv/lib/python3.9/site-packages/isort/api.py", line 264, in check_stream
    changed: bool = sort_stream(
  File "/home/flo/dev/redacted/.venv/lib/python3.9/site-packages/isort/api.py", line 218, in sort_stream
    raise FileSkipComment(content_source)
isort.exceptions.FileSkipComment: /home/flo/dev/redacted/__init__.py contains a file skip comment and was skipped.
karthiknadig commented 2 years ago

@fwindolf The server is redesigned a bit and should work better. Please try the pre-release version and see if that helps.