RSSAmplifier

Blog

Giampaolo Rodola

Python enthusiast, core developer, psutil author

gmpy.devRSS feed ↗33 posts

Latest posts

From Python 3.3 to today: ending 15 years of subprocess polling

One of the less fun aspects of process management on POSIX systems is waiting for a process to terminate. The standard library's subprocess module has relied on a busy-loop polling approach since the timeout parameter was added to subprocess.Popen.wait() in Python 3.3, around 15 years ago (see …

Detecting memory leaks in C extensions with psutil and psleak

Memory leaks in Python are usually straightforward to diagnose. Just look at RSS, track Python object counts, follow reference graphs, etc. But leaks inside C extension modules are another story. Traditional memory metrics such as RSS and VMS fail to reveal them because Python's memory allocator ( pymalloc ) sits above the …

Wheels for free-threaded Python now available

With the release of psutil 7.1.2, wheels for free-threaded Python are now available. This milestone was achieved largely through a community effort, as several internal refactorings to the C code were required to make it possible (see #2565 ). Many of these changes were contributed by Lysandros Nikolaou . Thanks …

Speeding up pytest startup

Preface: the migration to pytest ¶ Last year, after 17 years of unittest , I started adopting pytest in psutil (see #2446 ). The two advantages I cared about most were plain assert statements and pytest-xdist 's free parallelism. Tests still inherit from unittest.TestCase and there's no conftest.py or fixture use …

A Brave / Chrome extension to reorder new tabs

While browsing, I almost always keep three tabs open: Gmail, Slack, and Microsoft Teams (for work). I find it convenient to have them always in the same position (1, 2, and 3), so I can quickly switch to them using keyboard shortcuts ( alt+1 , alt+2 , alt+3 ). While the …

Letting go of Python 2.7

About dropping Python 2.7 support in psutil, 3 years ago I stated ( #2014 ): Not a chance, for many years to come. [Python 2.7] currently represents 7-10% of total downloads, meaning around 70k / 100k downloads per day. Only 3 years later, and to my surprise, downloads for Python 2 …

Recognize connection errors

Lately I've been dealing with an asynchronous TCP client app which sends messages to a remote server. Some of these messages are important, and cannot get lost. Because the connection may drop at any time, I had to implement a mechanism to resend the message once the client reconnects. As …

Sublime Text: remember cursor position plugin

My editor of choice for Python development is Sublime Text. It has been for a very long time (10 years). It's fast, minimalist and straight to the point, which is why I always resisted the temptation to use more advanced and modern IDEs such as PyCharm or VS code, which …

New Pelican website

Hello there. Here is my new blog / personal website! This is something I've been wanting to do for a very long time, since the old blog hosted at https://grodola.blogspot.com/ was... well, too old. =) This new site is based on Pelican , a static website generator similar to Jekyll …

System load average on Windows in Python

psutil 5.6.2 is out. It implements an emulation of os.getloadavg() on Windows, kindly contributed by Ammar Askar , who originally implemented it for CPython's test suite . This idea has been floating around for quite a while. The first proposal dates back to 2010 , when psutil was still hosted …

Announcing psutil 5.6.0

psutil 5.6.0 is out. Highlights: a new Process.parents() method, several important Windows improvements, and the removal of Process.memory_maps() on macOS. Process parents() ¶ The new method returns the parents of a process as a list of Process instances. If no parents are known, an empty list is …

Removing Process.memory_maps() on macOS

This is part of the psutil 5.6.0 release (see the full release notes ). As of 5.6.0, Process.memory_maps() is no longer defined on macOS. The bug ¶ #1291 : on macOS, Process.memory_maps() would either raise OSError: [Errno 22] Invalid argument or segfault the whole Python process! Both …

AIX support

After a long wait psutil finally supports a new exotic platform: AIX! Honestly I'm not sure how many AIX Python users are out there (probably not many), but here it is. For this we have to thank Arnon Yaari , who started working on the port a couple of years ago …

Announcing psutil 5.3.0

psutil 5.3.0 is finally out. This release is a major one, bigger than any release before it in terms of improvements and bugfixes. It is interesting to notice how huge the diff between 5.2.2 and 5.3.0 is. This is because I've been travelling quite …

Fixing Unicode across Python 2 and 3

This one took a while. Adding proper Unicode support to psutil took four months of auditing, design decisions, and rewriting nearly every API that returned a string. The full journey is documented in #1040 , and what follows is a summary. This can serve as a case study for any Python …

Improved process_iter()

This is part of the psutil 5.3.0 release (see the changelog for the full list of changes). The old pattern ¶ Iterating over processes and collecting attributes requires more boilerplate than it should. A process returned by psutil.process_iter() may disappear before you access it, or require elevated privileges …

Sensors: temperatures, battery, CPU frequency

psutil 5.1.0 is out. This release introduces new APIs to retrieve hardware temperatures, battery status, and CPU frequency information. Temperatures ¶ You can now retrieve hardware temperatures ( PR-962 ). This is currently available on Linux only. On Windows it's hard to do in a hardware-agnostic way. I ran into 3 …

Making psutil twice as fast

Starting from psutil 5.0.0 you can query multiple Process fields around twice as fast as before (see #799 and Process.oneshot() doc ). It took 7 months, 108 commits, and a massive refactoring of psutil internals ( PR-937 ), and I think it's one of the best improvements ever shipped in …

Improved Linux memory metrics

OK, another psutil release. The headline of 4.4.0 is more accurate memory metrics on Linux, plus a pile of macOS fixes I'd been sitting on for years. Linux virtual memory ¶ People had been complaining for a while that virtual_memory() didn't match what free reported on Linux ( #862 , #685 …

Windows services support

New psutil 4.2.0 is out. The highlight of this release is the support for Windows services (executables that run at system startup, similar to UNIX init scripts): >>> import psutil >>> list ( psutil . win_service_iter ()) [<WindowsService(name='AeLookupSvc', display_name='Application Experience') at 38850096>, <WindowsService(name='ALG', display_name='Application Layer Gateway Service …

NetBSD support

Roughly two months have passed since I last announced that psutil added support for OpenBSD. Today I'm happy to announce that it's the turn of NetBSD! This was contributed by Thomas Klausner , Ryo Onodera and myself in PR-557 . Differences with FreeBSD (and OpenBSD) ¶ The NetBSD implementation has limitations similar to …

Real process memory and environ in Python

psutil 4.0.0 is out, with some interesting news about process memory metrics. I'll get straight to the point and describe what's new. "Real" process memory info ¶ Determining how much memory a process really uses is not an easy matter (see this and this ). RSS (Resident Set Size), which …

How to always execute exit functions in Python

...or why atexit.register() and signal.signal() are evil UPDATE (2016-02-13) : this recipe no longer handles SIGINT , SIGQUIT and SIGABRT as aliases for "application exit" because it was a bad idea . It only handles SIGTERM . Also it no longer supports Windows because signal.signal() implementation is too different from POSIX …

OpenBSD support

Starting from version 3.3.0 (released just now) psutil officially supports OpenBSD. This was contributed by Landry Breuil and myself in PR-615 . Differences with FreeBSD ¶ As expected, the OpenBSD implementation is very similar to FreeBSD's, so I merged most of it into a single C file ( _psutil_bsd.c ), with …

Reimplementing ifconfig in Python

Here we are. It's been a long time since my last blog post and my last psutil release. The reason? I've been travelling! I mean... a lot. I've spent 3 months in Berlin, 3 weeks in Japan and 2 months in New York City. While I was there I finally …

Proper zombie process handling

This is part of the psutil 3.0 release (see the full release notes ). Except on Linux and Windows (which does not have them), support for zombie processes was broken. The full story is in #428 . The problem ¶ Say you create a zombie process and instantiate a Process for it …

Windows wheels available in psutil 2.1.2

psutil 2.1.2 is out. This release has been cooking for a while now, and that's because I've been travelling for the past 3 months between Spain, Japan and Germany. Hopefully I will be staying in Berlin for a while now, so I will have more time to dedicate …

Python and sendfile

sendfile(2) is a UNIX system call which provides a "zero-copy" way of copying data from one file descriptor (a file) to another (a socket). Because this copying is done entirely within the kernel, sendfile(2) is more efficient than the combination of file.read() and socket.send() , which requires …

Goodbye Google Code, I am moving to GitHub

8 years ago I started hosting my first open source project (pyftpdlib, code.google.com/p/pyftpdlib) on Google Code and I later ended up also hosting psutil (code.google.com/p/psutil) and pysendfile (code.google.com/p/pysendfile). Back then GC had just been released and similarly to …

Announcing psutil 2.0

psutil 2.0 is out. This is a major rewrite and reorganization of both the Python and C extension modules. It costed me four months of work and more than 22,000 lines (the diff against old 1.2.1). Many of the changes are not backward compatible; I'm sure …

Reimplementing netstat in Python

psutil 2.1.0 is out and with it I finally managed to implement something I've been wanting to have for a long time: netstat-like functionality (see ticket code.google.com/p/psutil/issues/detail?id=387). Similarly to "netstat -antp" on UNIX you can now list system-wide connections in …

Porting your code to psutil 2.0

This blog post is going to be about psutil 2.0, a major release in which I decided to reorganize the existing API for the sake of consistency. At the time of writing, psutil 2.0 is still under development, and the intent of this blog post is to serve …

Making constants part of your API is evil

One of the initial features which were included in psutil since day one (5 years ago) were the system's boot time, number of CPUs and total physical memory. These metrics have one thing in common: they are (apparently) not supposed to change over time. That is why Jay and I …