[python-win32] zmq under win32service

momchil at bojinov.info momchil at bojinov.info
Wed Mar 9 01:28:04 EST 2022


Morning guys,

I m fairly certain it is not a problem with the win32service code as it works just fine with a tcp socket
The actual service runs ok and is not stuck. It responds to stop command.
I don't mind sharing the code:
https://github.com/bozhinov/cache-poc

I guess 0mq is not the way to go for me.
I just need a piece of shared memory I can place structured data and access it from multiple processes.
Why is that so hard to do under Windows ?
No in-memory databases either and I m not using subsystem for linux

Momchil

-----Original Message-----
From: python-win32 <python-win32-bounces+momchil=bojinov.info at python.org> On Behalf Of Mark Hammond
Sent: Wednesday, March 9, 2022 7:00 AM
To: Tim Roberts <timr at probo.com>; python-win32 at python.org
Subject: Re: [python-win32] zmq under win32service

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

_______________________________________________
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