Pyzmq: Context.term() hangs

Created on 23 Apr 2011  路  5Comments  路  Source: zeromq/pyzmq

Hi,

I may found a bug in pyzmq or zeromq. When a request is sent on an host which is not connected
context.term() method will hang. I think the socket close method should discard every operations pending.

I don't know if it is an issue from zeromq or pyzmq, anyway here is the code to reproduce the bug.

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zmq
>>> ctx = zmq.Context()
>>> sock = ctx.socket(zmq.REQ)
>>> sock.connect("tcp://localhost:5000") # no zeromq socket listen here
>>> sock.send("lol")
>>> 
>>> sock.close()
>>> ctx.term() # this hangs

I use 2.1.4 version of zeromq and pyzmq.

Most helpful comment

Not a bug, see documentation of ZMQ_LINGER sockopt for explanation: http://api.zeromq.org/2-1-1:zmq-setsockopt

The default value is -1, which means wait until all messages have been sent before allowing termination. Set to 0 to discard unsent messages immediately, and any positive integer will be the number of milliseconds to keep trying to send before discard.

Calling:
sock.setsockopt(zmq.LINGER, n) with any non-negative integer n will prevent ctx.term() from hanging indefinitely.

All 5 comments

Not a bug, see documentation of ZMQ_LINGER sockopt for explanation: http://api.zeromq.org/2-1-1:zmq-setsockopt

The default value is -1, which means wait until all messages have been sent before allowing termination. Set to 0 to discard unsent messages immediately, and any positive integer will be the number of milliseconds to keep trying to send before discard.

Calling:
sock.setsockopt(zmq.LINGER, n) with any non-negative integer n will prevent ctx.term() from hanging indefinitely.

Ho, thank you !
Sorry for the noise.

I know this is a very old issue but I am using

In [18]: zmq.__version__
Out[18]: '2.0.10.1'

is there a way to set linger? for this version of pyzmq? Thanks

libzmq 2.0 does not have a LINGER option.

OK thanks. Guess it is time to upgrade. Thanks for your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SavageMessiah picture SavageMessiah  路  23Comments

simmdan picture simmdan  路  4Comments

mirceaulinic picture mirceaulinic  路  8Comments

ncarenton picture ncarenton  路  15Comments

Prokhozhijj picture Prokhozhijj  路  3Comments