Questions tagged [psutil]

psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python.

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5.

Resources:

481 questions
2
votes
1 answer

Python - error in mocking method that calls psutil.process_iter

I have a method (below), in a module utils.py that uses psutil.process_iter to find and generate process info. dicts (psutil.Process.as_dict) based on the name of a given process. If the process name doesn't exist, or process errors are encountered,…
srm
  • 548
  • 1
  • 4
  • 19
2
votes
0 answers

Detect memory swapping in Python

How to detect when OS starts swapping some resources of the running process to disk? I came here from basically the same question. The psutil library is obviously great and provides a lot of information, yet, I don't know how to use it to solve the…
Tomáš Hons
  • 355
  • 3
  • 11
2
votes
1 answer

Cannot mock method of mocked object? call_count is 0 in pytest

I have the following function in the file myfile.py: #myfile.py import psutil class RunnableObject: def run(self): parent = psutil.Process() print(parent) children = parent.children(recursive=True) …
user3302735
  • 69
  • 2
  • 9
2
votes
2 answers

psutil.Process and lsof command discrepancy

I've written a simple Python script that monitors the number of file descriptors on a Red Hat system. When comparing to the lsof command I get two different results. Broken down to it's core, the script does this: import psutil p =…
ap0
  • 1,083
  • 1
  • 12
  • 37
2
votes
1 answer

Incorrect Boot Time In `psutil.boot_time()` on windows with Python?

When running psutil.boot_time() for the first time (yesterday) on my windows computer it shows the correct boot time. But when I am running it today it shows yesterday's boot time! what to do? Am I Doing Something Wrong?
Dhruv_2676
  • 101
  • 1
  • 9
2
votes
1 answer

Python program with psutil fails after 8 hours of running with PermissionError: [WinError 5] Access is denied - why?

I have a Python 3.x program running in Windows that uses psutil. The job of this program is simple - to periodically check if a different program is running. If it finds the program, it does nothing. If it doesn't find the program, it starts the…
츄 plus
  • 488
  • 1
  • 7
  • 20
2
votes
1 answer

Failed building wheel for psutil on macOS

Problem I am trying to install psutil using pip so I ran pip install psutil but I receive the following error message: Failed building wheel for psutil Running setup.py clean for psutil What I have tried It seems like the problem is occurring…
user12128336
2
votes
0 answers

psutil - "System Idle Process" CPU percentage usage is over 100%

So I am trying to print every task's CPU percentage and memory percentage and it looks great but for some reason "System Idle Process" shows me above 100 CPU percentage e.g(312,201) in task manager it looks fine, e.g(89%, 93%) not over 100 why is…
Patch
  • 694
  • 1
  • 10
  • 29
2
votes
0 answers

Python - psutil.sensors_battery() returns None in Ubuntu

I have a Python script that runs in the background and checks various battery information with psutil in Python. The script worked perfectly back when I was using Windows, but after I switched to Ubuntu, I have problems with it. Whenever I run the…
Jaran Mellerud
  • 167
  • 1
  • 1
  • 7
2
votes
0 answers

Python program freezes after some hours

I wrote an extended Python program to control an aquaponic system with a Raspberry Pi (explanation in readme.md). Since some weeks, the program freezes after some hours. When starting, the CPU-percentage of Python3 is 7-8 %, Memory = 3-4%. After…
2
votes
1 answer

Python, equivalent to bash command for getting remote process' environment variables

I'm currently using the Bash command ps eww in order to get the environment variable of all processes. For example, If I run the following command : a=a b=b c=c sleep 1000 The output of ps eww | grep sleep would be: 23709 s007 S 0:00.00…
Zohar81
  • 4,554
  • 5
  • 29
  • 82
2
votes
1 answer

Python psutil memory_info caps at 4.0G

I am trying to list and sort all running processes in Windows by their memory consumption with the python psutil module. However when I query a processes memory_info attribute none of the various metrics will get above 4 gigabytes. Why is this…
Spencer
  • 1,931
  • 1
  • 21
  • 44
2
votes
1 answer

How to list daemon (services) process in linux, as with psutil?

I am trying to print the current running services (daemon process?) in linux using psutil In windows, using psutil I can get the currently running services with this code: def log(self): win_sev = set() for sev in…
user574362
  • 67
  • 1
  • 7
2
votes
3 answers

How to get the script path of a python process who's cmdline is ["python"], with no path?

I'm trying to get and kill all other running python instances of the same script, I found an edge case where the path is not in psutil's cmdline list, when the process is started with ./myscript.py and not python ./myscript.py the script's content…
Wis
  • 484
  • 7
  • 22
2
votes
2 answers

Gracefully kill Chrome for Windows with Python

I have been trying to determine a method to close Chrome (and other processes) gracefully utilizing Python. I have gone through a few methods but all result in Chrome displaying a message stating "Chrome didn't shut down correctly." with a Restore…
Sherd
  • 468
  • 7
  • 17