[python-win32] Wanted to know how we can overwrite the win32serviceutil.ServiceFramework SvcDoRun method.

pavi ena potterpavi at gmail.com
Thu Mar 29 16:24:45 CEST 2012


Hello,

I am new to Python Window services development. I have small code below.

from datetime import datetime
import time
import sys
import os

import win32service
import win32serviceutil
import win32api
import win32con

class DemoService(win32serviceutil.ServiceFramework):
    _svc_name_ = "DemoService"
    _svc_display_name_ = "DemoService"

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.isAlive = True
        self.args =  args

    def SvcDoRun(self):
        import servicemanager
        while self.isAlive:
            start_mail_check(args[2], args[3])
            self.isAlive = False

    def SvcStop(self):
        import servicemanager
        servicemanager.LogInfoMsg("ZetlConductorSvcs - Received stop
signal")
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        self.isAlive = False

def ctrlHandler(ctrlType):
    return True

def start_mail_check(user_id=None, passwd=None):
    if not user_id and not passwd:
        servicemanager.LogInfoMsg("DemoService - Invalid argument passed.")
    else:
       #Go ahead to download the mails from configured mail server.

def main():
   print ">>>", sys.argv, len(sys.argv)

if __name__ == '__main__':
    win32api.SetConsoleCtrlHandler(ctrlHandler, True)
    win32serviceutil.HandleCommandLine(DemoService, argv=sys.argv)

I use this script to run to download mails for different user_id and
password
from configured mail server.

Generally i run this script as batch file which takes parameters like
user_id
and password

python demo_svcs.py install
python demo_svcs.py start %user_id% %password%

At present in my code i am passing user_id and password as argv
 "win32serviceutil.HandleCommandLine(DemoService, argv=sys.argv)"
 which intern i am accessing these user_id and password in 'SvcDoRun'
method
 with 'args', i just wanted to know is this the correct approach or do we
have flexibility
 to overwrite 'SvcDoRun' method to get these 'user_id' and 'password' as
kwd_args
 and use these kwd_args in 'start_mail_check' method.

I want to run the same service with different user_id and password as
command line args
for multiple users.

I gooled to find out examples with with parameters, but i am not lucky
enough to find out.

Could any one suggest me move forward in this regard.

Thanks,
Pavi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120329/91765adc/attachment.html>


More information about the python-win32 mailing list