Hi there,
I have a python application (many python scripts) and I start the
application like this
python myServer.py start
in window. It is running in dos window. Now I would like to put it in
background as NT service. I got a example code: SmallestService .py from
chapter 18 of the book "Python Programming On Win32" by Mark Hammond
etc. The code is as follows and runs well as an NT service.
Since I don't have the book, anybody knows how to "insert" my "python
myServer.py start" into the sample code as follows.
Thanks a lot for your help.
ouyang
############### ############### ############### ########
import win32serviceuti l
import win32service
import win32event
class SmallestPythonS ervice(win32ser viceutil.Servic eFramework):
_svc_name_ = "SmallestPython Service"
_svc_display_na me_ = "The smallest possible Python Service"
def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
# And set my event.
win32event.SetE vent(self.hWait Stop)
def SvcDoRun(self):
# We do nothing other than wait to be stopped!
win32event.Wait ForSingleObject (self.hWaitStop ,
win32event.INFI NITE)
if __name__=='__ma in__':
win32serviceuti l.HandleCommand Line(SmallestPy thonService)
I have a python application (many python scripts) and I start the
application like this
python myServer.py start
in window. It is running in dos window. Now I would like to put it in
background as NT service. I got a example code: SmallestService .py from
chapter 18 of the book "Python Programming On Win32" by Mark Hammond
etc. The code is as follows and runs well as an NT service.
Since I don't have the book, anybody knows how to "insert" my "python
myServer.py start" into the sample code as follows.
Thanks a lot for your help.
ouyang
############### ############### ############### ########
import win32serviceuti l
import win32service
import win32event
class SmallestPythonS ervice(win32ser viceutil.Servic eFramework):
_svc_name_ = "SmallestPython Service"
_svc_display_na me_ = "The smallest possible Python Service"
def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
# And set my event.
win32event.SetE vent(self.hWait Stop)
def SvcDoRun(self):
# We do nothing other than wait to be stopped!
win32event.Wait ForSingleObject (self.hWaitStop ,
win32event.INFI NITE)
if __name__=='__ma in__':
win32serviceuti l.HandleCommand Line(SmallestPy thonService)
Comment