0

I am trying to setup a zmq socket inside a worker-task in python-rq.

If I create the context inside the task function:

def push( user, task_id, data ):
    """Push message to `user` over websocket.
    """


    ctx = zmq.Context()
    pub = ctx.socket( zmq.PUB )
    pub.connect( 'ipc:///tmp/message_flow_in' )

    pub.send( b"0 " + json.dumps( {'username': user,
                                   'id':       task_id,
                                   'data':     data
                                   }
                                  ).encode( 'utf-8' )
              )

the pub.send() call does nothing.

user3666197
  • 1
  • 6
  • 50
  • 92
kyrre
  • 626
  • 2
  • 9
  • 24
  • Have you tried the very same scenario with a **`tcp`**-based transport-class with **`flags = zmq.NOBLOCK`** for diagnostic purposes ( even for the case the both peers are hosted on the same localhost )? – user3666197 May 23 '16 at 18:25

1 Answers1

0

So I dont know python, so this may not be correct, but its very similar to a problems i've had with zeromq in c++ so :

When you call send the message isnt acctually sent, its copied to buffers within the socket/context for sending later by the context. So when your function returns and the local socket/context go out of scope, then the message likely gets deleted before its sent by the context.

David
  • 1,510
  • 14
  • 20