(level, pid=None)
Set the priority/nice of the application.
    
    Numbers may be used (in the style of Linux from -20 (high) to 19 (low),
    or as text, such as 'belownormal' or 'realtime'.
Set the priority/nice of the application.
    
    Numbers may be used (in the style of Linux from -20 (high) to 19 (low),
    or as text, such as 'belownormal' or 'realtime'.
Set the priority / nice of the application . Numbers may be used ( in the style of Linux from - 20 ( high ) to 19 ( low ) or as text such as belownormal or realtime .
def set_priority(level, pid=None):
    """Set the priority/nice of the application.
    
    Numbers may be used (in the style of Linux from -20 (high) to 19 (low),
    or as text, such as 'belownormal' or 'realtime'.
    """
    process = psutil.Process(pid)
    try:
        level = level.lower().replace(' ', '')
        
        if level == 'realtime':
            process.nice(psutil.REALTIME_PRIORITY_CLASS)
        elif level == 'high':
            process.nice(psutil.HIGH_PRIORITY_CLASS)
        elif level == 'abovenormal':
            process.nice(psutil.ABOVE_NORMAL_PRIORITY_CLASS)
        elif level == 'normal':
            process.nice(psutil.NORMAL_PRIORITY_CLASS)
        elif level == 'belownormal':
            process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)
        if level == 'low':
            process.nice(psutil.IDLE_PRIORITY_CLASS)
            
    except AttributeError:
        if level < -13:
            process.nice(psutil.REALTIME_PRIORITY_CLASS)
        elif -13 <= level < -7:
            process.nice(psutil.HIGH_PRIORITY_CLASS)
        elif -7 <= level < 0:
            process.nice(psutil.ABOVE_NORMAL_PRIORITY_CLASS)
        elif 0 <= level < 7:
            process.nice(psutil.NORMAL_PRIORITY_CLASS)
        elif 7 <= level < 12:
            process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)
        elif 13 <= level:
            process.nice(psutil.IDLE_PRIORITY_CLASS)
def set_priority ( level , pid = None ) : process = psutil . Process ( pid ) try : level = level . lower ( ) . replace ( ' ' , '' ) if level == 'realtime' : process . nice ( psutil . REALTIME_PRIORITY_CLASS ) elif level == 'high' : process . nice ( psutil . HIGH_PRIORITY_CLASS ) elif level == 'abovenormal' : process . nice ( psutil . ABOVE_NORMAL_PRIORITY_CLASS ) elif level == 'normal' : process . nice ( psutil . NORMAL_PRIORITY_CLASS ) elif level == 'belownormal' : process . nice ( psutil . BELOW_NORMAL_PRIORITY_CLASS ) if level == 'low' : process . nice ( psutil . IDLE_PRIORITY_CLASS ) except AttributeError : if level < - 13 : process . nice ( psutil . REALTIME_PRIORITY_CLASS ) elif - 13 <= level < - 7 : process . nice ( psutil . HIGH_PRIORITY_CLASS ) elif - 7 <= level < 0 : process . nice ( psutil . ABOVE_NORMAL_PRIORITY_CLASS ) elif 0 <= level < 7 : process . nice ( psutil . NORMAL_PRIORITY_CLASS ) elif 7 <= level < 12 : process . nice ( psutil . BELOW_NORMAL_PRIORITY_CLASS ) elif 13 <= level : process . nice ( psutil . IDLE_PRIORITY_CLASS )