# encoding: utf-8 # # Task sink - design 2 # Adds pub-sub flow to send kill signal to workers # # Author: Jeremy Avnet (brainsik) # import sys import time import zmq context = zmq.Context() # Socket to receive messages on receiver = context.socket(zmq.PULL) receiver.bind("tcp://*:5558") # Socket for worker control controller = context.socket(zmq.PUB) controller.bind("tcp://*:5559") # Wait for start of batch receiver.recv() # Start our clock now tstart = time.time() # Process 100 confirmiations for task_nbr in range(100): receiver.recv() if task_nbr % 10 == 0: sys.stdout.write(":") else: sys.stdout.write(".") sys.stdout.flush() # Calculate and report duration of batch tend = time.time() tdiff = tend - tstart total_msec = tdiff * 1000 print("\nTotal elapsed time: %d msec" % total_msec) # Send kill signal to workers controller.send(b"KILL") # Finished receiver.close() controller.close() context.term()