Larry Bates wrote:
Something that runs all day in the background is a perfect candidate
for being turned into a Service. That and servicemanager has a good
way of managing the task so that it doesn't take up lots of excess
CPU cycles that a "normal" application would take while sleeping
or unnecessarily looping. Pick up a copy of Mark Hammond's Python
Programming on Win32 book for example services in Python. You could
then start/stop the service with service manager or with net start/
net stop commands.
-Larry Bates
Bell, Kevin wrote: Great! And now that it's hiding w/ .pyw, how would I kill it if I want?
Just log off, or is there a better way?
Kevin
It is possible to get a background process in windows especially with
Python-2.4, but it's fairly hard.
try using
python runner.py dingo.py
where
###### runner.py
def bgScript(script,scriptArgs):
from _subprocess import CreateProcess
class STARTUPINFO:
dwFlags = 0
hStdInput = None
hStdOutput = None
hStdError = None
class pywintypes:
error = IOError
import sys
exe = sys.executable.replace('n.exe','nw.exe')
startupinfo = STARTUPINFO()
args = ''.join([' "%s"' % a for a in scriptArgs])
cmd = '"%s" "%s" %s' % (exe,script,args)
try:
hp, ht, pid, tid = CreateProcess(None, cmd,
# no special security
None, None,
0, #don't inherit standard handles
0x208,
None,
None,
startupinfo)
except pywintypes.error, e:
print str(e)
if __name__=='__main__':
import sys
bgScript(sys.argv[1],sys.argv[2:])
###### dingo.py
if __name__=='__main__':
import time
for i in xrange(15):
time.sleep(1)
######
dingo.py shoul be running in the background detached from the console.
Of course as others point out, the official way to do this stuff is to
use all the M$ paraphernalia and have stuff start up at boot time etc etc.
--
Robin Becker