Python zmq.POLLERR Examples

The following are 5 code examples of zmq.POLLERR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module zmq , or try the search function .
Example #1
Source File: poll.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def _get_descriptors(self):
        """Returns three elements tuple with socket descriptors ready
        for gevent.select.select
        """
        rlist = []
        wlist = []
        xlist = []

        for socket, flags in self.sockets:
            if isinstance(socket, zmq.Socket):
                rlist.append(socket.getsockopt(zmq.FD))
                continue
            elif isinstance(socket, int):
                fd = socket
            elif hasattr(socket, 'fileno'):
                try:
                    fd = int(socket.fileno())
                except:
                    raise ValueError('fileno() must return an valid integer fd')
            else:
                raise TypeError('Socket must be a 0MQ socket, an integer fd '
                                'or have a fileno() method: %r' % socket)

            if flags & zmq.POLLIN:
                rlist.append(fd)
            if flags & zmq.POLLOUT:
                wlist.append(fd)
            if flags & zmq.POLLERR:
                xlist.append(fd)

        return (rlist, wlist, xlist) 
Example #2
Source File: poll.py    From Computable with MIT License 5 votes vote down vote up
def _get_descriptors(self):
        """Returns three elements tuple with socket descriptors ready
        for gevent.select.select
        """
        rlist = []
        wlist = []
        xlist = []

        for socket, flags in self.sockets:
            if isinstance(socket, zmq.Socket):
                rlist.append(socket.getsockopt(zmq.FD))
                continue
            elif isinstance(socket, int):
                fd = socket
            elif hasattr(socket, 'fileno'):
                try:
                    fd = int(socket.fileno())
                except:
                    raise ValueError('fileno() must return an valid integer fd')
            else:
                raise TypeError('Socket must be a 0MQ socket, an integer fd '
                                'or have a fileno() method: %r' % socket)

            if flags & zmq.POLLIN:
                rlist.append(fd)
            if flags & zmq.POLLOUT:
                wlist.append(fd)
            if flags & zmq.POLLERR:
                xlist.append(fd)

        return (rlist, wlist, xlist) 
Example #3
Source File: poll.py    From pySINDy with MIT License 5 votes vote down vote up
def _get_descriptors(self):
        """Returns three elements tuple with socket descriptors ready
        for gevent.select.select
        """
        rlist = []
        wlist = []
        xlist = []

        for socket, flags in self.sockets:
            if isinstance(socket, zmq.Socket):
                rlist.append(socket.getsockopt(zmq.FD))
                continue
            elif isinstance(socket, int):
                fd = socket
            elif hasattr(socket, 'fileno'):
                try:
                    fd = int(socket.fileno())
                except:
                    raise ValueError('fileno() must return an valid integer fd')
            else:
                raise TypeError('Socket must be a 0MQ socket, an integer fd '
                                'or have a fileno() method: %r' % socket)

            if flags & zmq.POLLIN:
                rlist.append(fd)
            if flags & zmq.POLLOUT:
                wlist.append(fd)
            if flags & zmq.POLLERR:
                xlist.append(fd)

        return (rlist, wlist, xlist) 
Example #4
Source File: poll.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_descriptors(self):
        """Returns three elements tuple with socket descriptors ready
        for gevent.select.select
        """
        rlist = []
        wlist = []
        xlist = []

        for socket, flags in self.sockets:
            if isinstance(socket, zmq.Socket):
                rlist.append(socket.getsockopt(zmq.FD))
                continue
            elif isinstance(socket, int):
                fd = socket
            elif hasattr(socket, 'fileno'):
                try:
                    fd = int(socket.fileno())
                except:
                    raise ValueError('fileno() must return an valid integer fd')
            else:
                raise TypeError('Socket must be a 0MQ socket, an integer fd '
                                'or have a fileno() method: %r' % socket)

            if flags & zmq.POLLIN:
                rlist.append(fd)
            if flags & zmq.POLLOUT:
                wlist.append(fd)
            if flags & zmq.POLLERR:
                xlist.append(fd)

        return (rlist, wlist, xlist) 
Example #5
Source File: controllers.py    From cstar_perf with Apache License 2.0 4 votes vote down vote up
def console_messages(ws):
    """Receive console messages as they happen

    ZMQ message format:
     Console messages:
      console cluster_name {"job_id":"current_job_id", "msg":"message from console"}
     Control messages:
      Keep alive:
      The cluster is starting a job:
       console cluster_name {"job_id":"current_job_id", "ctl":"START"}
      The cluster finished a job:
       console cluster_name {"job_id":"current_job_id", "ctl":"DONE"}
      The cluster is not working on anything:
       console cluster_name {"ctl":"IDLE"}

    When forwarding messages to the websocket client, the "console cluster_name" 
    portion is dropped and just the JSON is sent.

    Websocket sends keepalive messages periodically:
     {"ctl":"KEEPALIVE"}

    """
    cluster_name = ws.receive()
    console_socket = console_subscribe(cluster_name)
    try:
        while True:
            try:
                data = console_socket.recv_string()
                data = data.lstrip("console {cluster_name} ".format(cluster_name=cluster_name))
                ws.send(data)
            except zmq.error.Again:
                # If we timeout from zmq, send a keep alive request to the
                # websocket client:
                ws.send('{"ctl":"KEEPALIVE"}')
                # The client websocket will send keepalive back:
                ws.receive()
            except zmq.error.ZMQError, e:

                if e.errno == zmq.POLLERR:
                    log.error(e)
                    # Interrupted zmq socket code, reinitialize:
                    # I get this when I resize my terminal.. WTF?
                    console_socket = setup_zmq()
    finally:
        log.error("Unsubscribing from zmq socket")
        console_socket.setsockopt_string(zmq.UNSUBSCRIBE, u'')