98 words
1 minute
Using psutil to investigate "Too many open files"
Anubhav Gain
2024-01-29

Using psutil to investigate “Too many open files”#

I was getting this intermittent error running my Datasette test suite:

OSError: [Errno 24] Too many open files

To figure out what was going on, I used the psutil package and its open_files() method.

Here’s the documentation for psutil.Process.open_files.

I ran pip install psutil in my virtual environment.

Then I ran pytest --pdb to drop into a Python debugger when a test failed.

In the debugger I ran this:

import psutil
for f in psutil.Process().open_files(): print(f)

This showed the current list of open files for that process, which gave me some clues to help me start resolving the problem.

Using psutil to investigate "Too many open files"
https://mranv.pages.dev/posts/using-psutil-to-investigate-too-many-open-files/
Author
Anubhav Gain
Published at
2024-01-29
License
CC BY-NC-SA 4.0