(self, process, method, accessors=None, *args, **kwargs)
return result
A psutil wrapper that is calling
        * psutil.method(*args, **kwargs) and returns the result
        OR
        * psutil.method(*args, **kwargs).accessor[i] for each accessors
        given in a list, the result being indexed in a dictionary
        by the accessor name
A psutil wrapper that is calling
        * psutil.method(*args, **kwargs) and returns the result
        OR
        * psutil.method(*args, **kwargs).accessor[i] for each accessors
        given in a list, the result being indexed in a dictionary
        by the accessor name
A psutil wrapper that is calling * psutil . method ( * args ** kwargs ) and returns the result OR * psutil . method ( * args ** kwargs ) . accessor [ i ] for each accessors given in a list the result being indexed in a dictionary by the accessor name
def psutil_wrapper(self, process, method, accessors=None, *args, **kwargs):
        """
        A psutil wrapper that is calling
        * psutil.method(*args, **kwargs) and returns the result
        OR
        * psutil.method(*args, **kwargs).accessor[i] for each accessors
        given in a list, the result being indexed in a dictionary
        by the accessor name
        """

        if accessors is None:
            result = None
        else:
            result = {}

        # Ban certain method that we know fail
        if method == 'num_fds' and not Platform.is_unix():
            return result
        elif method == 'num_handles' and not Platform.is_win32():
            return result

        # Try running `num_fds` with sudo if possible
        if method == 'num_fds' and self.try_sudo:
            self.log.debug("Running num_fds using sudo")
            try:
                ls_args = ['sudo', 'ls', '/proc/{}/fd/'.format(process.pid)]
                process_ls = subprocess.check_output(ls_args)
                result = len(process_ls.splitlines())
            except Exception as e:
                self.log.exception("Trying to retrieve %s with sudo failed with error: %s", method, e)

        else:
            try:
                res = getattr(process, method)(*args, **kwargs)
                if accessors is None:
                    result = res
                else:
                    for acc in accessors:
                        try:
                            result[acc] = getattr(res, acc)
                        except AttributeError:
                            self.log.debug("psutil.%s().%s attribute does not exist", method, acc)
            except (NotImplementedError, AttributeError):
                self.log.debug("psutil method %s not implemented", method)
            except psutil.AccessDenied:
                self.log.debug("psutil was denied access for method %s", method)
            except psutil.NoSuchProcess:
                self.log.debug("Process %s disappeared while scanning", process.pid)

        return result
def psutil_wrapper ( self , process , method , accessors = None , * args , * * kwargs ) : if accessors is None : result = None else : result = { } # Ban certain method that we know fail if method == 'num_fds' and not Platform . is_unix ( ) : return result elif method == 'num_handles' and not Platform . is_win32 ( ) : return result # Try running `num_fds` with sudo if possible if method == 'num_fds' and self . try_sudo : self . log . debug ( "Running num_fds using sudo" ) try : ls_args = [ 'sudo' , 'ls' , '/proc/{}/fd/' . format ( process . pid ) ] process_ls = subprocess . check_output ( ls_args ) result = len ( process_ls . splitlines ( ) ) except Exception as e : self . log . exception ( "Trying to retrieve %s with sudo failed with error: %s" , method , e ) else : try : res = getattr ( process , method ) ( * args , * * kwargs ) if accessors is None : result = res else : for acc in accessors : try : result [ acc ] = getattr ( res , acc ) except AttributeError : self . log . debug ( "psutil.%s().%s attribute does not exist" , method , acc ) except ( NotImplementedError , AttributeError ) : self . log . debug ( "psutil method %s not implemented" , method ) except psutil . AccessDenied : self . log . debug ( "psutil was denied access for method %s" , method ) except psutil . NoSuchProcess : self . log . debug ( "Process %s disappeared while scanning" , process . pid ) return result