Windows Services
rodmc
userprogoogle-139 at yahoo.co.uk
Tue Apr 4 09:06:39 EDT 2006
Hello,
I am trying to figure out how to write a windows service, I am totally
new to it. I have written a simple test case, however it doesn't appear
to do anything. Although it installs and appears to start, when I run a
query of its status (using another app) it says it is not running. As
a note I am running it as the administrator in a Win2k machine to avoid
any problems with permissions - although I would rather not do this for
ever :-)
I install the software as follows:
python testservice.py install
python testservice.py start
I am sure I am missing something out as I am basically working from
code samples for other solutions which I have seen. In particular one
for getting CherryPy to run as a service.
When I have figured this all out I intend to add in some code I have
already written which runs a server application.
It may be all rather obvious but I am quite new Python (just a few
months) and totally new to Windows services.
Thanks in advance for any help.
Best,
Rod
import win32serviceutil
import win32service
import win32event
import os,sys
class helloworld:
def test(self):
x=1
filename=open("c:test.txt","w")
while x<100000:
print >>filename,x
x=x+1
class MyService(win32serviceutil.ServiceFramework):
"""NT Service."""
_svc_name_ = "Test"
_svc_display_name_ = "Test"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that SvcDoRun can wait on and SvcStop
# can set.
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
print "got here"
helloworld.test()
win32event.WaitForSingleObject(self.stop_event,
win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
if __name__ == '__main__':
win32serviceutil.HandleCommandL
More information about the Python-list
mailing list