parameters: ()
docstring: Return a generator yielding a Process instance for all
      running processes.
  
      Every new Process instance is only created once and then cached
      into an internal table which is updated every time this is used.
  
      Cached Process instances are checked for identity so that you're
      safe in case a PID has been reused by another process, in which
      case the cached instance is updated.
  
      The sorting order in which processes are yielded is based on
      their PIDs.
docstring_summary: Return a generator yielding a Process instance for all
      running processes.
docstring_tokens: Return a generator yielding a Process instance for all running processes .
function: def process_iter():
      """Return a generator yielding a Process instance for all
      running processes.
  
      Every new Process instance is only created once and then cached
      into an internal table which is updated every time this is used.
  
      Cached Process instances are checked for identity so that you're
      safe in case a PID has been reused by another process, in which
      case the cached instance is updated.
  
      The sorting order in which processes are yielded is based on
      their PIDs.
      """
      def add(pid):
          proc = Process(pid)
          _pmap[proc.pid] = proc
          return proc
  
      def remove(pid):
          _pmap.pop(pid, None)
  
      a = set(pids())
      b = set(_pmap.keys())
      new_pids = a - b
      gone_pids = b - a
  
      for pid in gone_pids:
          remove(pid)
      for pid, proc in sorted(list(_pmap.items()) +
                              list(dict.fromkeys(new_pids).items())):
          try:
              if proc is None:  # new process
                  yield add(pid)
              else:
                  # use is_running() to check whether PID has been reused by
                  # another process in which case yield a new Process instance
                  if proc.is_running():
                      yield proc
                  else:
                      yield add(pid)
          except NoSuchProcess:
              remove(pid)
          except AccessDenied:
              # Process creation time can't be determined hence there's
              # no way to tell whether the pid of the cached process
              # has been reused. Just return the cached version.
              yield proc
function_tokens: def process_iter ( ) : def add ( pid ) : proc = Process ( pid ) _pmap [ proc . pid ] = proc return proc def remove ( pid ) : _pmap . pop ( pid , None ) a = set ( pids ( ) ) b = set ( _pmap . keys ( ) ) new_pids = a - b gone_pids = b - a for pid in gone_pids : remove ( pid ) for pid , proc in sorted ( list ( _pmap . items ( ) ) + list ( dict . fromkeys ( new_pids ) . items ( ) ) ) : try : if proc is None : # new process yield add ( pid ) else : # use is_running() to check whether PID has been reused by # another process in which case yield a new Process instance if proc . is_running ( ) : yield proc else : yield add ( pid ) except NoSuchProcess : remove ( pid ) except AccessDenied : # Process creation time can't be determined hence there's # no way to tell whether the pid of the cached process # has been reused. Just return the cached version. yield proc