question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python dev container keeps getting high cpu usage

See original GitHub issue

Type: Bug

devcontainer.json:

{
  "name": "Python-3.10.8",
  "build": {
    "dockerfile": "Dockerfile"
  },
  "extensions": [
    "ms-python.python@2022.10.0",
    "sourcery.sourcery@0.12.3",
    "esbenp.prettier-vscode@9.8.0"
  ],
  "remoteUser": "python"
}

Dockerfile:

FROM python:3.10.8

ARG USERNAME=python
ARG PASSWORD=alskdj
ARG DEBIAN_FRONTEND=noninteractive

USER root

RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install -y \
        git \
        vim

RUN useradd \
    -u 1474 \
    -p $(openssl passwd -1 $PASSWORD) \
    -s /usr/bin/bash \
    --create-home \
    ${USERNAME}

RUN usermod -aG sudo ${USERNAME} && \
    echo "${USERNAME}:${PASSWORD}" | chpasswd

COPY .bashrc /home/${USERNAME}

COPY .ssh /home/${USERNAME}/.ssh
RUN chmod 400 /home/${USERNAME}/.ssh/id* /home/${USERNAME}/.ssh/config

RUN chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}

USER ${USERNAME}

Opening this file with errors makes my CPU usage more than 100%:

from fastapi import FastAPI

from app.handlers.events.startup import startup
from app.routers.queue import get_queue_router


# TODO: how are dependencies cached?
# if we define a global dependency and call it elsewhere, is it cached?
def create_application() -> FastAPI:
    app = FastAPI()

    app.include_router(get_queue_router())

    return app


_app = create_application()


# TODO: force singleton db to be created
@_app.on_event("startup")  # type:ignore
def startup_handler() -> None:
    startup()


# TODO: cleanup db
@_app.on_event("shutdown")  # type:ignore
def shutdown_handler() -> None:
    pass


@_app.get("/")
def root_handler() -> dict[str, str]:
    return {"message": "Hello, world!"}

top output:

top - 19:50:15 up 11:08,  0 users,  load average: 1.56, 1.43, 1.18
Tasks:  27 total,   2 running,  25 sleeping,   0 stopped,   0 zombie
%Cpu(s): 19.0 us,  2.0 sy,  0.0 ni, 79.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15709.0 total,   3309.1 free,   3663.3 used,   8736.6 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.  11224.1 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                               
   3196 python    20   0 1121188 380948  35040 R 100.3   2.4   5:53.82 node                                  
    210 python    20   0  779352  54404  32612 S   0.7   0.3   0:05.45 node                                  
   3129 python    20   0 1050156 183300  42564 S   0.7   1.1   1:49.27 node                                  
   3087 python    20   0  590008  46540  29788 S   0.3   0.3   0:00.76 node                                  
      1 python    20   0    2484   1484   1396 S   0.0   0.0   0:00.82 sh                                    
    133 python    20   0    2484    572    504 S   0.0   0.0   0:00.03 sh                                    
    145 python    20   0  618000  34392  27552 S   0.0   0.2   0:00.12 node                                  
    151 python    20   0    2484    572    504 S   0.0   0.0   0:00.03 sh                                    
    161 python    20   0  961660 104308  35256 S   0.0   0.6   1:01.02 node                                  
   1762 python    20   0    2484    576    508 S   0.0   0.0   0:00.02 sh                                    
   1807 python    20   0  618000  34644  27804 S   0.0   0.2   0:00.12 node                                  
   1883 python    20   0    2484    572    504 S   0.0   0.0   0:00.02 sh                                    
   2133 python    20   0    7132   4980   3292 S   0.0   0.0   0:00.01 bash                                  
   2893 python    20   0    2484   1656   1568 S   0.0   0.0   0:00.01 sh                                    
   2916 root      20   0    2484    508    444 S   0.0   0.0   0:00.02 sh                                    
   2949 python    20   0    2484    576    508 S   0.0   0.0   0:00.02 sh                                    
   3029 python    20   0  618000  34620  27776 S   0.0   0.2   0:00.13 node                                  
   3104 python    20   0  595956  52136  29716 S   0.0   0.3   0:04.38 node                                  
   3106 python    20   0  966316  43192  31900 S   0.0   0.3   0:00.44 node                                  
   3191 python    20   0  924340 252144 106708 S   0.0   1.6   1:01.39 sourcery                              
   3247 python    20   0    2484    572    504 S   0.0   0.0   0:00.02 sh                                    
   9181 python    20   0  663732  60316  31792 S   0.0   0.4   0:00.76 node

Pylance stops working

VS Code version: Code 1.71.2 (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:12:14.256Z) OS version: Linux x64 5.15.0-50-generic Modes: Sandboxed: No Remote OS version: Linux x64 5.15.0-50-generic

System Info
Item Value
CPUs Intel® Core™ i7-10510U CPU @ 1.80GHz (8 x 2300)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 2, 1, 1
Memory (System) 15.34GB (10.98GB free)
Process Argv . --crash-reporter-id 77a8fa93-6940-434f-9a12-36d9bb7a8bb4
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
Item Value
Remote Dev Container: Python-3.10.8
OS Linux x64 5.15.0-50-generic
CPUs Intel® Core™ i7-10510U CPU @ 1.80GHz (8 x 2300)
Memory (System) 15.34GB (10.99GB free)
VM 0%
Extensions (15)
Extension Author (truncated) Version
endwise kai 1.5.1
jupyter-keymap ms- 1.0.0
remote-containers ms- 0.255.4
remote-ssh ms- 0.90.1
remote-ssh-edit ms- 0.84.0
remote-wsl ms- 0.66.3
vscode-remote-extensionpack ms- 0.21.0
vscode-ruby win 0.28.0
prettier-vscode esb 9.9.0
python ms- 2022.16.1
vscode-pylance ms- 2022.10.30
jupyter ms- 2022.8.1002431955
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.9
sourcery sou 0.12.11
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
i497e931:30553904
pyindex848:30577860
nodejswelcome1:30587005
fc301958:30573243

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Dec 19, 2022

@doublethink13 if this hasn’t happened since the latest updates I’m going to go ahead and close this issue. If it comes up again and appears to be Pylance, you can open an issue at https://github.com/microsoft/pylance-release .

0reactions
doublethink13commented, Dec 19, 2022

If I was to disable Pylance, no, this wouldn’t happen.

Currently I’m on:

Version: 1.74.0
Commit: 5235c6bb189b60b01b1f49062f4ffa42384f8c91
Date: 2022-12-05T16:47:18.476Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 5.15.0-56-generic
Sandboxed: No

This has not happened again since upgrading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python dev container keeps getting high cpu usage #20377
FROM python:3.10.8 ARG USERNAME=python ARG PASSWORD=alskdj ARG DEBIAN_FRONTEND=noninteractive USER root RUN apt-get update -y && \ apt-get ...
Read more >
Docker hyperkit process CPU usage going crazy. How to keep ...
I am currently running 8 containers (6 Python and 2 node) with file watchers on and my CPU is at 25% usage. Share....
Read more >
Dev Containers Tips and Tricks - Visual Studio Code
First, try stopping any running containers you are no longer using. If this doesn't solve your problem, you may want to see if...
Read more >
High CPU usage for Django application
The CPU usage for com.docker.driver.amd64-linux sits at around 100% and the osxfs process at around 50% while the application is idle.
Read more >
Kubernetes Logging: Tips to Avoid Memory and Resource ...
If there is more CPU or RAM available on the host, a container can use more resources than specified in requests. Resource limits:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found