I am using the SURVEY scalability protocol with nanomsg in Python.
I have a bunch of respondent sockets, I connect a surveyor to them
in a loop; then, I wait for surveyor.send_fd to be readable. I assume it is connected to at least one respondent,
then I send the survey.
On the respondent side, I wait for respondent.recv_fd to be readable, and I call respondent.recv()
to know about the
survey, then I send the answer.
Back to the surveyor, I wait for surveyor.recv_fd to be
readable and I call surveyor.recv()
to get answers from respondents.
Sometimes I get an error when trying to read answers from respondents:
Traceback (most recent call last):
[...]
nanomsg.NanoMsgAPIError: Operation cannot be performed in this state
I simplify the code to show the issue:
test_respondent.py
import nanomsg
import select
resp = nanomsg.Socket(nanomsg.RESPONDENT)
resp.bind("tcp://*:6542")
print 'waiting for respondent to be readable'
select.select([resp.recv_fd],[],[])
print 'receiving survey'
print resp.recv(flags=nanomsg.DONTWAIT)
print 'sending reply to surveyor'
resp.send("reply")
test_surveyor.py
import select
import nanomsg
s = nanomsg.Socket(nanomsg.SURVEYOR)
s.connect("tcp://127.0.0.1:6542")
print 'waiting for surveyor to be connected'
select.select([s.send_fd],[],[])
s.send("hello", nanomsg.DONTWAIT)
print "waiting for surveyor to be readable"
select.select([s.recv_fd],[],[])
print 'receiving reply from respondent'
print s.recv(flags=nanomsg.DONTWAIT)
test.sh
python test_respondent.py &
python test_surveyor.py
Executing the test several times should lead to the exception described above in some cases.
Any idea what I am doing wrong ? And how to fix the problem ?