[python-win32] zmq under win32service
Mark Hammond
skippy.hammond at gmail.com
Wed Mar 9 00:00:05 EST 2022
I admit I've never fully understood the threading model used to control
services, and agree that almost every "real" service will create threads
- but it's not clear to me that they *must* - eg, I've seen demo
services that use a similar loop, and
https://github.com/mhammond/pywin32/blob/main/win32/Demos/service/serviceEvents.py
has:
def SvcDoRun(self):
# do nothing at all - just wait to be stopped
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
and seems to work. So I could understand if the symptoms reported here
were along the lines of "windows thinks my service has hung and killed
it" or something similar, but it's not clear to me that the lack of a
worker thread is the reason the service can't make it a single time
around that loop.
Cheers,
Mark
On 9/03/2022 8:41 am, Tim Roberts wrote:
> momchil at bojinov.info wrote:
>>
>> server:
>>
>> import zmq, json
>>
>> context = zmq.Context()
>>
>> socket = context.socket(zmq.REP)
>>
>> socket.bind('ipc://cache/mm')
>>
>> while True:
>>
>> message = socket.recv_json()
>>
>> print(message)
>>
>> socket.send_json(json.dumps({"data" : "BLA BLA"}))
>>
>> Once I start the service though I can’t send/receive content
>>
>> Both service and cmd/client run under the same account (not SYSTEM)
>>
> Where is the service code?
>
>
>> I was wondering if I can even use while True without the spawning a
>> separate thread for it ?
>>
> No. Just like a Windows GUI app, a Windows service has a main message
> loop that has to remain in control, so it can receive and dispatch
> messages from the service manager. The system sends "are you awake?"
> messages periodically to make sure you're still alive. If you aren't
> getting back to the main loop, then you will be terminated.
>
> So, if you're using the sample you mentioned, the service "def
> main(self):" will need to launch a thread to do your listening. You will
> also need to have your thread check the "stop_request" flag, so you can
> cleanly exit when the service is terminated.
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
More information about the python-win32
mailing list