Skip to content

[Linux] psutil.process_iter(attrs=['num_fds']) yielded an object with proc.info['num_fds'] = None #2831

Description

@vkruglik-aka

Summary

  • OS: Linux
  • Architecture: 64bit
  • Psutil version: psutil==7.2.1
  • Python version: 3.13
  • Type: core

Description

The function below the traceback was being executed periodically for many hours without failure, but then failed because psutil.process_iter(attrs=['num_fds']) yielded an object with proc.info['num_fds'] = None:

The Traceback snippet:

_get_allocated_file_descriptor_count_in_container
    total_fds += proc.info['num_fds']
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

Is this the expected behavior? I don't recall seeing this in the documentation.

The Function:

    def _get_allocated_file_descriptor_count_in_container(self) -> int:
        """Return the total number of file descriptors of all types currently allocated by
        all process in our docker container using psutil.
        """
        total_fds: int = 0
        # NOTE: specifying 'num_fds' in attrs arg is an optimization that instructs psutil to
        # only retrieve the number of fds for each process, which is all we need, instead of
        # retrieving all info for each process, which is more expensive.
        for proc in psutil.process_iter(attrs=['num_fds']):
            try:
                total_fds += proc.info['num_fds']
            except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
                # Ignore processes that close or restricted processes (root/system)
                continue
        return total_fds

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions