#!/usr/bin/python

# tz_os_priority.py
#       --copyright--                   Copyright 2010 (C) Tranzoa, Co. All rights reserved.    Warranty: You're free and on your own here. This code is not necessarily up-to-date or of public quality.
#       --url--                         http://www.tranzoa.net/tzpython/
#       --email--                       pycode is the name to send to. tranzoa.com is the place to send to.
#       --bodstamps--
#       May 25, 2010            bar
#       May 27, 2012            bar     doxygen namespace
#       --eodstamps--
##      \file
#       \namespace              tzpython.tz_os_priority
#
#
#       Allow others to get the current thread or process to run at idle priority.
#
#


import  os


try :
    import  win32process
except ImportError  :
    win32process    = None


def set_proc_to_idle_priority(better_than_idle = 0) :
    better_than_idle    = better_than_idle or 0
    if  win32process    :
        phnd            = win32process.GetCurrentProcess()
        # orgp          = win32process.GetPriorityClass(phnd)
        win32process.SetPriorityClass(phnd, win32process.IDLE_PRIORITY_CLASS - better_than_idle)
    else                :
        try :
            os.nice(10 - better_than_idle)          # well, it's close enough
        except AttributeError :
            pass
        pass
    pass

#
#
#
if __name__ == '__main__' :

    set_proc_to_idle_priority(1)

    while True :
        pass
    pass


#
#
#
# eof
