pythonvisual-studio-codepylancevscode-devcontainerdevcontainer

Pylance in devcontainer is loading forever


I am trying to set up a devcontainer on my desktop, but functions like autocomplete or go to function don't work. When I hover variable or function it shows never-ending load information Loading information. I was trying use different Pylance versions and different images but results were the same. I have this problem with Jupyter notebooks and regular python files. Only noticeable thing that I saw was progressive usage of RAM throught the resource monitor in VS Code. When RAM hits the threshold of 6.5GB, then it suddenly decrease to 2.5GB and Pylance switch port to a different one. This cycle repeats infinitely. Also, I got this message Enumeration of workspace even if workspace directory contains only test file like this.

test = 'test' 
print(test)

Notebooks and files are executing normally. I was using Pylance 2025.7.1, VS Code 1.102.3, Docker 4.43.1 with WSL 2.5.9.0 and Windows 11.

Dockerfile

FROM pytorch/pytorch:2.7.1-cuda12.8-cudnn9-devel
RUN apt-get update && apt-get upgrade -y
RUN apt-get -y install git
RUN pip install jupyter ipykernel packaging ninja mlflow tqdm torchinfo matplotlib
RUN pip install flash-attn --no-build-isolation
RUN pip install "unsloth[cu128-torch271] @ git+https://github.com/unslothai/unsloth.git"
RUN pip install triton --extra-index-url "https://download.pytorch.org/whl/cu128"

Docker-compose.yaml

services:
  pytorch:
    container_name: pytorch
    build: 
        context: .
        dockerfile: Dockerfile
    ports:
        - "8888:8888"
    environment:
        - JUPYTER_TOKEN=easy
    working_dir: /
    volumes:
        - ../:/workspace
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              capabilities: ["gpu"]
              device_ids: ["0"]
    command: sleep infinity

devcontainer.json

{
    "name": "Pytorch_devcontainer",
    "dockerComposeFile": "./docker-compose.yaml",
    "workspaceFolder": "/",
    "shutdownAction": "stopCompose",
    "service": "pytorch",
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-toolsai.jupyter",
                "ms-toolsai.vscode-jupyter-cell-tags",
                "ms-toolsai.jupyter-renderers",
                "ms-toolsai.vscode-jupyter-slideshow",
                "christian-kohler.path-intellisense",
                "ms-python.vscode-pylance",
                "ms-python.python",
                "mutantdino.resourcemonitor",
                "redhat.vscode-yaml"
            ]
        }
    }


}

Solution

  • Restrict your workspace to just the folder you actually care about. Change your devcontainer.json so that VS Code’s workspace is /workspace (location of the ode), not /.