'Shut down paired listener with <END> signal.'

def shutdown(self):

    if hasattr(self, 'socket'):
        try:
            self.socket.send_unicode('<END>', zmq.NOBLOCK)
        except zmq.error.ZMQError:
            try:
                self.socket.recv_unicode(zmq.NOBLOCK)
                self.socket.send_unicode('<END>', zmq.NOBLOCK)
            except zmq.error.ZMQError:
                pass
    if hasattr(self, 'process'):
        try:
            self.process.communicate(timeout=1)
        except subprocess.TimeoutExpired:
            self.process.kill()
