title: Python multithreaded ZeroMQ REQ-REP
body: <p>I am looking to implement a REQ-REP pattern with Python and ZeroMQ using multithreading.</p>
  
  <p>With Python, I can create a new thread when a new client connects to the server. This thread will handle all communications with that particular client, until the socket is closed:</p>
  
  <pre><code># Thread that will handle client's requests
  class ClientThread(threading.Thread):
      # Implementation...
      def __init__(self, socket):
          threading.Thread.__init__(self)
          self.socket = socket
      def run(self):
          while keep_alive:
              # Thread can receive from client
              data = self.socket.recv(1024)
              # Processing...
              # And send back a reply
              self.socket.send(reply)
  
  while True:
      # The server accepts an incoming connection
      conn, addr = sock.accept()
      # And creates a new thread to handle the client's requests
      newthread = ClientThread(conn)
      # Starting the thread
      newthread.start()
  </code></pre>
  
  <p>Is it possible to do the same[*] using ZeroMQ? I have seen some examples of multithreading with ZeroMQ and Python, but in all of them a pool of threads is created with a fixed number of threads at the beginning and it seems to be more oriented to load balancing.</p>
  
  <p>[*] Notice what I want is to keep the connection between a client and its thread alive, as the thread is expecting multiple REQ messages from the client and it will store information that must be kept between messages (i.e.: a variable counter that increments its value on a new REQ message; so each thread has its own variable and no other client should ever be able to access that thread). New client = new thread.</p>