Ubuntu: what is python and why does it use so much cpu periodically?


I have a Compaq V5205 with 1.46g celeron CPU. I am relatively happy with the performance as I mostly just check email and browse the internet. However, sometimes the system slows to a crawl. I launched system monitor and noticed the phyton was using 100% of the cpu! Python stopped just as I saw what was happening so I didn't get any more info.


Long Answer

The General Python FAQ states:

Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on Windows 2000 and later.

In this context, there are 3 important facets: (Bolded)

  1. An interpreted language is a programming language for which most of its implementations execute instructions directly, without previously compiling a program into machine-language instructions.
  2. Interactive programming is the procedure of writing parts of a program while it is already active. This focuses on the program text as the main interface for a running process, rather than an interactive application, where the program is designed in development cycles and used thereafter (usually by a so-called "user", in distinction to the "developer"). Consequently, here, the activity of writing a program becomes part of the program itself.
  3. Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self"). In OOP, computer programs are designed by making them out of objects that interact with one another. There is significant diversity of OOP languages, but the most popular ones are class-based, meaning that objects are instances of classes, which typically also determine their type.

Why This is Important

All Linux'es main method of doing things, irrespective of the Window or Desktop Environment is the terminal, commonly called the TTY. Since the main method of input into the TTY is the keyboard, scripting became the main method of automating things, and while there are plenty of native scripting tools on Linux, like Awk/gAwk and Sed, some like Awk and Sed, are sometimes challenging for beginning scriptors, and challenging syntactically for even experts.

Since Python is a scripting language, it can be used in place of the tedious tools like those I noted. The OOP part comes in handy, as I can use the methods of the language, instead of having to write sed or awk snippets over and over again. And that is what most modern Linux'es have done to ease development, and scripting among developers. One of your programs is using some python script, and is hung.

Short Answer

Knowing that python is a scripting language means that @mikewhatever and I are correct in telling you that your system is running a program that is invoking a python script, and the script is taking a long time to execute or is hung. Tools like top, htop, and system monitor will tell you the name of the running script, and possibly the parent program that invoked the script.


Unfortunately, I do not currently have the ability to comment on this Stack Exchange site, but I will attempt to make this answer more complete than a comment. (I would recommend accepting eyoung100's detailed answer.)

Python is a scripting language that is used in many programs. When you see "python" in the process list, it is actually the python interpreter running a different program, in the same way as running a .JAR file would be displayed as "java".

The most notable program I notice that runs on python is playonlinux. Whenever I start playonlinux, both "playonlinux" and "python" appear in the system monitor, however they do not use very much of the CPU. The same would probably apply to most other programs that rely on Python, so you may want to check if any of your programs may possibly use the language.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »