title: How to use inproc transport with pyzmq?
body: <p>I have set up two small scripts imitating a publish and subscribe procedure with pyzmq. However, I am unable to send messages over to my subscriber client using the <code>inproc</code> transport. I am able to use <code>tcp://127.0.0.1:8080</code> fine, just not inproc.</p>
  
  <p><strong>pub_server.py</strong></p>
  
  <pre><code>import zmq
  import random
  import sys
  import time
  
  context = zmq.Context()
  socket = context.socket(zmq.PUB)
  socket.bind("inproc://stream")
  
  while True:
      socket.send_string("Hello")
      time.sleep(1)
  </code></pre>
  
  <p><strong>sub_client.py</strong></p>
  
  <pre><code>import sys
  import zmq
  
  # Socket to talk to server
  context = zmq.Context()
  socket = context.socket(zmq.SUB)
  socket.setsockopt_string(zmq.SUBSCRIBE, '')
  socket.connect("inproc://stream")
  
  for x in range (5):
      string = socket.recv()
      print(string)
  </code></pre>
  
  <p>How can I successfully alter my code so that I'm able to use the inproc transport method between my two scripts?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have updated my code to further reflect @larsks comment. I am still not receiving my published string - what is it that I am doing wrong?</p>
  
  <pre><code>import threading
  import zmq
  
  def pub():
      context = zmq.Context()
      sender = context.socket(zmq.PUB)
      sender.connect("inproc://hello")
      lock = threading.RLock()
  
      with lock:
          sender.send(b"")
  
  def sub():
      context = zmq.Context()
      receiver = context.socket(zmq.SUB)
      receiver.bind("inproc://hello")
  
      pub()
  
      # Wait for signal
      string = receiver.recv()
      print(string)
      print("Test successful!")
  
      receiver.close()
  
  if __name__ == "__main__":
      sub()
  </code></pre>