I'm trying to create a Windows Service that implements a DICOM listener with pynetdicom. I can create a simple program built around the AE class and run it successfully, and I can create a Windows service successfully, but I can't combine them.
I've attached the attempt, and copied it below in text.
For proof of concept, I just want to field a CEcho. The AE sees the echo request, and creates an association, but never calls the OnReceiveEcho function. It also never sees another echo, so assuming it locks up. The port is locked up as well.
Any help would be enormously appreciated.
Mike B.
import win32service
import win32serviceutil
import win32event
import os
import sys
import subprocess
from netdicom import AE, StorageSOPClass, VerificationSOPClass
class PySvc(win32serviceutil.ServiceFramework, AE):
LocalDicomAETitle = 'MyAE'
LocalDicomPort = 2100
_listenerSubproc = None
_myAE = None
# you can NET START/STOP the service by the following name
_svc_name_ = "DICOMCombinedListenerTestService"
# this text shows up as the service name in the Service
# Control Manager (SCM)
_svc_display_name_ = "DICOM Listener Service Test"
# this text shows up as the description in the SCM
_svc_description_ = "A DICOM Listener for entering plan data to the Staging db"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
# create an event to listen for stop requests on
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def MyOnReceiveEcho(self):
print "Echo received"
# core logic of the service
def SvcDoRun(self):
# start AE
print "starting AE ... "
_myAE = AE(self.LocalDicomAETitle, self.LocalDicomPort, [StorageSOPClass, VerificationSOPClass], [StorageSOPClass, VerificationSOPClass])
_myAE.OnReceiveEcho = self.MyOnReceiveEcho
_myAE.start()
rc = None
# if the stop event hasn't been fired keep looping
while rc != win32event.WAIT_OBJECT_0:
# block for 5 seconds and listen for a stop event
rc = win32event.WaitForSingleObject(self.hWaitStop, 10000)
print 'waited'
_myAE.Quit()
# called when we're being shut down
def SvcStop(self):
# kill the listener subprocess
self._listenerSubproc.terminate()
# tell the SCM we're shutting down
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# fire the stop event
win32event.SetEvent(self.hWaitStop)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(PySvc)