views:

129

answers:

3

Is it possible for a python script to execute at a low run level?

Edit: To clarify, is it possible for a python script to run in the background, kind of like a daemon.

+4  A: 

I put this file nice.py in my site-packages directory (on Windows):

import win32api,win32process,win32con
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CLASS)

Then I just import nice on any script I want to run at reduced priority.

Paul McGuire
+1 whether it answers the question or not (whatever the question actually was.. who knows?). This could be quite useful along with `multiprocessing` to spawn off a secondary process that can do background work with minimal impact on the main process for a high-responsiveness application.
Peter Hansen
A: 

I'm sorry my question was unclear. I meant to ask if it was possible for a python script to run in the background, kind of like a daemon. (Linux)

pub
Yes, it is possible.
Jason Orendorff
Instead of answering your own question, you should add new information by editing the question itself.
MAK
A: 

Yes. The scripts that control daemons are (normally) plain old bash scripts and can run whatever a bash script can run. The only difference is that in a low runlevel, lots of other system services will not be running, so if the program tries to do something that depends on another daemon, that may fail.

Jason Orendorff