2

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 ?

mguijarr
  • 7,641
  • 6
  • 45
  • 72
  • There is an answer for a similar question. http://stackoverflow.com/questions/31071644/surveyor-respondent-patter-in-nanomsg-in-python/31072730#31072730 – Davoud Taghawi-Nejad Jun 26 '15 at 12:05
  • thanks! In fact, the bug is supposed to be fixed... Look at the discussion in github issue #414 and commit: https://github.com/nanomsg/nanomsg/commit/e2811f22afa1cc68b79bab82c8e66b36823e48be – mguijarr Jun 26 '15 at 12:55

0 Answers0