
    ^j	                    ,    d Z ddlmZ ddgZddZd	dZy)
zHelpers for inspecting Linux process state from ``/proc``.

These are intentionally agent-agnostic so they can be reused outside of
``torch.distributed.elastic.agent``.
    )annotationsread_proc_stateis_uninterruptible_statec                    	 t        d|  d      5 }|j                         }ddd       j                  d      }|dk(  ry||dz   d j                         }|sy|d   S # 1 sw Y   >xY w# t        $ r Y yw xY w)a  Read the process state char from ``/proc/<pid>/stat``. Linux-only.

    Returns the single-letter state (e.g. ``'R'``, ``'S'``, ``'D'``,
    ``'Z'``) or ``None`` if the file is unreadable (non-Linux, process
    gone, permission denied, or parse error). The ``comm`` field can
    contain spaces and parentheses, so the parser keys off the last
    ``)`` rather than splitting on whitespace.
    z/proc/z/statN)   r   )openreadrfindsplitOSError)pidfdatarparenrests        x/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/distributed/elastic/utils/process_state.pyr   r      s    F3%u%& 	!668D	CR< FQJL!'')Aw	 	  s3   A+ AA+ A+ A+ A($A+ +	A76A7c                0    | duxr | j                  d      S )zReturn True if ``state`` is Linux uninterruptible sleep ('D').

    Includes the ``'D+'`` (foreground) variant; the state field is
    a single char in the kernel format we read, but we accept any
    string that starts with ``'D'`` defensively.
    ND)
startswith)states    r   r   r   /   s     6!1!1#!66    N)r   intreturn
str | None)r   r   r   bool)__doc__
__future__r   __all__r   r    r   r   <module>r"      s&    # 8
927r   