Python ZeroMQ PUSH/PULL — Lost Messages?

后端 未结 2 1017
小鲜肉
小鲜肉 2021-02-09 01:20

I am trying to use python with zeroMQ in PUSH / PULL mode, sending messages of size 4[MB] every few seconds.

For

2条回答
  •  长情又很酷
    2021-02-09 01:53

    The problem is that when the program exits, the socket gets closed immediately and garbage collected with an effective LINGER of 0 (i.e. it throws any unsent messages away). This is a problem for larger messages because they take longer to send than it takes for the socket to be garbage collected.

    You can avoid this by putting a sleep(0.1) just before the program exits (to delay the socket and context being garbage collected).

    socket.setsockopt(zmq.LINGER, -1) (which is the default) should avoid this problem, but it doesn't for some reason that I haven't had time to investigate.

提交回复
热议问题