I am coding my first windows service, in python and have a few issues. I am including only the part of the code up until the issue
Logon_Service.py
class EditService (win32serviceutil.ServiceFramework):
_svc_name_ = "Edit Login Service"
_svc_display_name_ = "Edit Login Service"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.stop_event = win32event.CreateEvent(None,0,0,None)
socket.setdefaulttimeout(60)
self.stop_requested = False
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
logging.info('Stopping service ...')
self.stop_requested = True
def SvcDoRun(self):
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_,'')
)
self.main()
def main(self):
while 1:
if self.stop_requested:
logging.info('A stop signal was received, breaking loop')
break
repo = AvidRepo(r"C:\Users\Administrator\Desktop\WorkGroups",r"C:\LogonTemp")
repo.downloadSettings()
repo.validateSettings()
db = r"C:\Users\Administrator\Desktop\WorkGroups\test.db"
key = repo.workgroupRegKey
listofvalues = read_registry(key)
currentWorkgroup = [f for f in listofvalues if f.startswith(r"/Avid/Workgroup-")]
#if list index out of range
groupNumber = currentWorkgroup[0][-2:]
#Update Current Workgroup File
currentWorkgroupFile = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"Workgroup\AvidWorkgroup.txt")
shutil.move(currentWorkgroupFile,repo.workgroupFile)
#Update Current BGInfo File
currentBGInfo = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"BGINFO\x64Client.bgi")
shutil.move(currentBGInfo,repo.bgLocation)
time.sleep(5)
#Execute New BGInfo File
dir= ""
cmd = r"cmd C:\BGInfo\Bginfo.exe /ic:\BGinfo\x64Client.bgi /timer:0 /silent /NOLICPROMPT"
ret = call(cmd)
Service does not stop cleanly - and the subprocess.call() command does not work as well. When stopping the service, it continuously tries until it times out. the subprocess.call works from external to the service, but not in the service.
ANy ideas?