title: How could I set hwm in the push/pull pattern of zmq?
body: <p>I have found a similar question, <a href="https://stackoverflow.com/questions/21133535/zeromq-hwm-on-push-does-not-work">ZeroMQ: HWM on PUSH does not work</a>, but it couldn't solve my problem.</p>
  
  <p>I want to control the number of messages that the push socket queues, but it doesn't work and still queues 1000 messages.<br>
  So I want to know how to set the hwm of the push socket. Thanks in advance.  </p>
  
  <p>My environment is: libzmq 4.0.4, pyzmq 14.1.0, python 3.3  </p>
  
  <p>Here's my code:</p>
  
  <p>server.py  </p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  
  import random
  
  import zmq
  
  
  class TestPush(object):
  
      def __init__(self):
          self.ctx = zmq.Context()
  
          random.seed()
  
      def run(self):
          task_snd = self.ctx.socket(zmq.PUSH)
          task_snd.setsockopt(zmq.SNDHWM, 10)
          task_snd.bind('tcp://*:53000')        
  
          while True:
              workload = str(random.randint(1, 100))
              task_snd.send(workload.encode('utf-8'))
              print('Send {0}'.format(workload))
  
  
  if __name__ == '__main__':
      test_push = TestPush()
      test_push.run()
  </code></pre>
  
  <p>client.py  </p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  
  import time
  import random
  
  import zmq
  
  
  class TestPull(object):
  
      def __init__(self):
          self.ctx = zmq.Context()
  
      def run(self):
          task_rcv = self.ctx.socket(zmq.PULL)
          task_rcv.setsockopt(zmq.RCVHWM, 1)
          task_rcv.connect('tcp://localhost:53000')
  
          while True:
              msg = task_rcv.recv()
              print('Receive msg: {0}'.format(msg))
  
              time.sleep(random.randint(2, 3))
  
  
  if __name__ == '__main__':
      test_pull = TestPull()
      test_pull.run()
  </code></pre>