[python-win32] Re: how to run python in background on Windows ?

Larry Bates lbates at syscononline.com
Fri Jun 4 13:01:24 EDT 2004


>[snip]
>Is there anyone there knowing how to run python in background as Windows' 
>service ?

You can write an NT Service that runs all the time in the
background and sleeps for predetermined intervals then
wakes up and does something.  This program never exits
unless you stop the service.  This is good for things 
that need to be running all the time to take action when
something happens.

Services are somewhat hard to write, but are more efficient if
startup cost of the program is high and/or the times 
between when you wish to check are short.  An alternative
method would be to schedule jobs in the Task Scheduler.
If you schedule jobs to close together, you can run into 
the problem of the first job not completing before the 
second one starts.  NT services run to completion, then 
sleeps for a predetermined number of milliseconds so 
overlap is not a problem and the sleep mechanism doesn't
tie up the CPU.

If you want to learn about writing Python services you 
should get a copy of Mark Hammond's Python Programming
on Win32.  It has several examples that helped me a lot.

HTH,
Larry Bates
Syscon, Inc.




More information about the Python-win32 mailing list