[python-win32] zmq under win32service

Tim Roberts timr at probo.com
Tue Mar 8 16:41:42 EST 2022


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.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3389 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://mail.python.org/pipermail/python-win32/attachments/20220308/82d91b57/attachment.bin>


More information about the python-win32 mailing list