Python Shell High CPU Usage
Asked Answered
W

1

1

I have Python 3.4.3 installed on an older laptop (Pentium 4) with Windows XP.

It seems that half the time when the Python shell is open, the CPU usage goes up to 12-13%.

It is the Python shell itself, not any Python script it may have launched, and not the IDLE text editor.

I have yet to figure out the pattern when it goes up and when it does not. CPU usage actually goes to zero when I begin to debug a tkinter based script.

The shell window is opened by clicking on IDLE shortcut, if it makes any difference.

I have resorted to closing the shell until I need it, while I am working in IDLE editor.

Any idea why this happens and can this be remedied?

Webb answered 13/9, 2015 at 15:40 Comment(5)
Are you running the shell from a command prompt/terminal? If not, do you see the same spike when you do so?Poler
I have just edited my post. The shell gets launched by clicking on IDLE shortcut. I have not tried running it from command prompt and I do not have access to the machine right now.Webb
The shell window open by the Idle shortcut is Idle's tkinter-based shell connected to a second Python process. On Windows, watching the Task Manager Performance tab, I see a temporary spike when I open Idle for 3.5.0.Bull
I have observed it on two different computers, both running Windows XP. It is definitely not a single temporary spike, but a steady CPU usage. I have not observed this high CPU usage when the shell is run in a terminal, only with IDLE based shell. Which is unfortunate, because I like IDLE shell much better than the standard Windows command prompt.Webb
The name of the process using the CPU is pythonw.exe.Webb
B
0

IDLE normally runs in two processes: one to run the graphical user interface, one to run your code. The processes currently communicate through a socket. Each process polls the socket for input 20 times a second. The user process also calls tk update in case the use is using tkinter but is not running mainloop.

I have a 6-core Pentium with gigabytes of memory and SSD main drive running 64-bit Win10. I currently have 5 IDLE shells running and 5 corresponding user processes: installed 2.7, 3.4, 3.5, 3.6, and development build of 3.6. Task Manager mostly shows each at 0%. One occasionally bumps up to .7%. This would be a much higher % on a single core machine. This seems to happen more often with the 3.4 IDLE.

I can only speculate that some combination of less memory, slower memory, less CPU cache space, much slower swap to disk, old single-core laptop chip with fewer instructions, and older OS with fewer system calls results in the difference.

Does your laptop have its maximum memory?

How often when using IDLE is the 12% an actual problem? (I guess that partly depend on time on battery versus power cord.)

Bull answered 6/8, 2016 at 21:55 Comment(1)
I have observed this on two laptops - one is a Pentium 4 with 2GB of memory (maxed out) and the other is Pentium 3 with 1GB of memory (also maxed out). As best I can tell, the 12% usage is roughly 35-40% of the time. It goes to zero if I close the IDLE shell, but keep the IDLE editor open. Maybe I need to try a newer version and see if it helps. I do not operate them on battery. I will see if I can come up with a series of steps to reproduce the problem. Thanks.Webb

© 2022 - 2024 — McMap. All rights reserved.