renice

Carl Banks pavlovevidence at gmail.com
Fri Oct 26 18:45:01 EDT 2007


On Oct 26, 12:46 pm, Dan <thermos... at gmail.com> wrote:
> On Oct 26, 4:30 am, mokhtar <mbmessa... at yahoo.com> wrote:
>
> > Hi
>
> > Is it possible to renice the python process executing the current python
> > script ?:confused:
> > --
> > View this message in context:http://www.nabble.com/renice-tf4695834.html#a13422771
> > Sent from the Python - python-list mailing list archive at Nabble.com.
>
> On UNIX:>>> import os
> >>> os.system("renice -n %d %d" % ( new_nice, os.getpid() ) )


Hmm.  That seems to be the hard way, since you can set the nice value
of the current process (almost) directly:

import os
nice_adder = new_nice - os.nice(0)
os.nice(nice_adder)


But I suppose it could be useful in situations where you need
privleges you don't currently have. E.g.:

os.system("sudo renice -n %s %s" % (new_nice, os.getpid()))


Carl Banks





More information about the Python-list mailing list