python类POLLERR的实例源码

serialposix.py 文件源码 项目:btc-fpga-miner 作者: marsohod4you 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read)
serialposix.py 文件源码 项目:btc-fpga-miner 作者: marsohod4you 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read)
asyncore.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error()
manager.py 文件源码 项目:parallel-ssh 作者: shekkbuilder 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def poll(self, timeout=None):
        """Performs a poll and dispatches the resulting events."""
        if not self.readmap and not self.writemap:
            return
        try:
            event_list = self._poller.poll(timeout)
        except select.error:
            _, e, _ = sys.exc_info()
            errno = e.args[0]
            if errno == EINTR:
                return
            else:
                raise
        for fd, event in event_list:
            if event & (select.POLLIN | select.POLLHUP):
                handler = self.readmap[fd]
                handler(fd, self)
            if event & (select.POLLOUT | select.POLLERR):
                handler = self.writemap[fd]
                handler(fd, self)
asyncore.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def poll2(timeout=0.0, map=None):
    # Use the poll() support added to the select module in Python 2.0
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)
    pollster = select.poll()
    if map:
        for fd, obj in map.items():
            flags = 0
            if obj.readable():
                flags |= select.POLLIN | select.POLLPRI
            if obj.writable():
                flags |= select.POLLOUT
            if flags:
                # Only check for exceptions if object was either readable
                # or writable.
                flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
                pollster.register(fd, flags)
        try:
            r = pollster.poll(timeout)
        except select.error, err:
            if err.args[0] != EINTR:
                raise
            r = []
        for fd, flags in r:
            obj = map.get(fd)
            if obj is None:
                continue
            readwrite(obj, flags)
client.py 文件源码 项目:pypilot 作者: pypilot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def poll(self, timeout = 0):
        t0 = time.time()
        self.socket.flush()
        events = self.poller.poll(1000.0 * timeout)
        if events != []:
            event = events.pop()
            fd, flag = event
            if flag & (select.POLLERR | select.POLLNVAL):
                raise ConnectionLost
            if flag & select.POLLIN:
                if self.socket and not self.socket.recv():
                    raise ConnectionLost
                return True
        return False
server.py 文件源码 项目:pypilot 作者: pypilot 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def PollSockets(self):
        events = self.poller.poll(0)
        while events:
            event = events.pop()
            fd, flag = event
            socket = self.fd_to_socket[fd]
            if socket == self.server_socket:
                connection, address = socket.accept()
                if len(self.sockets) == max_connections:
                    print 'max connections reached!!!', len(self.sockets)
                    self.RemoveSocket(self.sockets[0]) # dump first socket??

                socket = LineBufferedNonBlockingSocket(connection)
                self.sockets.append(socket)
                fd = socket.socket.fileno()
                # print 'new client', address, fd
                self.fd_to_socket[fd] = socket
                self.poller.register(fd, select.POLLIN)
            elif flag & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
                self.RemoveSocket(socket)
            elif flag & select.POLLIN:
                if not socket.recv():
                    self.RemoveSocket(socket)
                while True:
                    line = socket.readline()
                    if not line:
                        break
                    try:
                        self.HandleRequest(socket, line)
                    except:
                        print 'invalid request from socket', line
                        socket.send('invalid request: ' + line + '\n')

        # flush all sockets
        for socket in self.sockets:
            socket.flush()
connection.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def connect(self, timeout=None, optimist=False):
        if timeout != None:
            limit = time.time() + timeout
        while True:
            if timeout != None and time.time() > limit:
                raise ConnectionTimeout('connection attempt timed out')
            try:
                Connection.connect(self)
            except ConnectionInProgress:
                if timeout == None:
                    events = self.poll(select.POLLOUT, -1)
                else:
                    events = self.poll(select.POLLOUT, timeout)
                if not events:
                    raise ConnectionTimeout('connection attempt timed out')
                if events[0][1] & (select.POLLERR | select.POLLHUP):
                    if optimist:
                        time.sleep(0.1)
                        continue
                    raise ConnectionRefused()
                if events[0][1] & select.POLLOUT:
                    e = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
                    if e == errno.ECONNREFUSED:
                        raise ConnectionRefused()
                    return
            return # good
connection.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def accept(self, timeout=None):
        if timeout == None:
            timeout = -1
        events = self.poll(select.POLLIN | errmask, timeout)
        if not events:
            raise ConnectionTimeout('nothing to accept')
        if events[0][1] & (select.POLLHUP | select.POLLERR):
            raise ConnectionClosed('error condition on socket')
        return Connection.accept(self, Class=BlockingConnection)
control.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def event_str(event):
    r = []
    if event & select.POLLIN:
        r.append('IN')
    if event & select.POLLOUT:
        r.append('OUT')
    if event & select.POLLPRI:
        r.append('PRI')
    if event & select.POLLERR:
        r.append('ERR')
    if event & select.POLLHUP:
        r.append('HUP')
    if event & select.POLLNVAL:
        r.append('NVAL')
    return ' '.join(r)
spool.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def register(self, fd):
        '''
        Register a file decriptor with the spool.
        '''
        if not self.fds:
            self.fds = select.poll()
        mask = (
            select.POLLERR | select.POLLHUP | select.POLLNVAL | select.POLLIN |
            select.POLLPRI
        )
        self.fds.register(fd, mask)
connection.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def connect(self, timeout=None, optimist=False):
        if timeout != None:
            limit = time.time() + timeout
        while True:
            if timeout != None and time.time() > limit:
                raise ConnectionTimeout('connection attempt timed out')
            try:
                Connection.connect(self)
            except ConnectionInProgress:
                if timeout == None:
                    events = self.poll(select.POLLOUT, -1)
                else:
                    events = self.poll(select.POLLOUT, timeout)
                if not events:
                    raise ConnectionTimeout('connection attempt timed out')
                if events[0][1] & (select.POLLERR | select.POLLHUP):
                    if optimist:
                        time.sleep(0.1)
                        continue
                    raise ConnectionRefused()
                if events[0][1] & select.POLLOUT:
                    e = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
                    if e == errno.ECONNREFUSED:
                        raise ConnectionRefused()
                    return
            return # good
connection.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def accept(self, timeout=None):
        if timeout == None:
            timeout = -1
        events = self.poll(select.POLLIN | errmask, timeout)
        if not events:
            raise ConnectionTimeout('nothing to accept')
        if events[0][1] & (select.POLLHUP | select.POLLERR):
            raise ConnectionClosed('error condition on socket')
        return Connection.accept(self, Class=BlockingConnection)
spool.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def register(self, fd):
        '''
        Register a file decriptor with the spool.
        '''
        if not self.fds:
            self.fds = select.poll()
        mask = (
            select.POLLERR | select.POLLHUP | select.POLLNVAL | select.POLLIN |
            select.POLLPRI
        )
        self.fds.register(fd, mask)
query.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _poll_for(fd, readable, writable, error, timeout):
    """Poll polling backend.
    @param fd: File descriptor
    @type fd: int
    @param readable: Whether to wait for readability
    @type readable: bool
    @param writable: Whether to wait for writability
    @type writable: bool
    @param timeout: Deadline timeout (expiration time, in seconds)
    @type timeout: float
    @return True on success, False on timeout
    """
    event_mask = 0
    if readable:
        event_mask |= select.POLLIN
    if writable:
        event_mask |= select.POLLOUT
    if error:
        event_mask |= select.POLLERR

    pollable = select.poll()
    pollable.register(fd, event_mask)

    if timeout:
        event_list = pollable.poll(long(timeout * 1000))
    else:
        event_list = pollable.poll()

    return bool(event_list)
asyncore.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def poll2(timeout=0.0, map=None):
    # Use the poll() support added to the select module in Python 2.0
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)
    pollster = select.poll()
    if map:
        for fd, obj in map.items():
            flags = 0
            if obj.readable():
                flags |= select.POLLIN | select.POLLPRI
            # accepting sockets should not be writable
            if obj.writable() and not obj.accepting:
                flags |= select.POLLOUT
            if flags:
                # Only check for exceptions if object was either readable
                # or writable.
                flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
                pollster.register(fd, flags)
        try:
            r = pollster.poll(timeout)
        except select.error, err:
            if err.args[0] != EINTR:
                raise
            r = []
        for fd, flags in r:
            obj = map.get(fd)
            if obj is None:
                continue
            readwrite(obj, flags)
e2reactor.py 文件源码 项目:enigma2 作者: OpenLD 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def register(self, fd, eventmask = select.POLLIN | select.POLLERR | select.POLLOUT):
        self.dict[fd] = eventmask
query.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _poll_for(fd, readable, writable, error, timeout):
    """Poll polling backend.
    @param fd: File descriptor
    @type fd: int
    @param readable: Whether to wait for readability
    @type readable: bool
    @param writable: Whether to wait for writability
    @type writable: bool
    @param timeout: Deadline timeout (expiration time, in seconds)
    @type timeout: float
    @return True on success, False on timeout
    """
    event_mask = 0
    if readable:
        event_mask |= select.POLLIN
    if writable:
        event_mask |= select.POLLOUT
    if error:
        event_mask |= select.POLLERR

    pollable = select.poll()
    pollable.register(fd, event_mask)

    if timeout:
        event_list = pollable.poll(long(timeout * 1000))
    else:
        event_list = pollable.poll()

    return bool(event_list)
serialposix.py 文件源码 项目:android3dblendermouse 作者: sketchpunk 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def read(self, size=1):
        """\
        Read size bytes from the serial port. If a timeout is set it may
        return less characters as requested. With no timeout it will block
        until the requested number of bytes is read.
        """
        if self.fd is None:
            raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN | select.POLLERR | select.POLLHUP | select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout * 1000):
                    if event & (select.POLLERR | select.POLLHUP | select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or
                        (self._inter_byte_timeout is not None and self._inter_byte_timeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read)
query.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _poll_for(fd, readable, writable, error, timeout):
    """Poll polling backend.
    @param fd: File descriptor
    @type fd: int
    @param readable: Whether to wait for readability
    @type readable: bool
    @param writable: Whether to wait for writability
    @type writable: bool
    @param timeout: Deadline timeout (expiration time, in seconds)
    @type timeout: float
    @return True on success, False on timeout
    """
    event_mask = 0
    if readable:
        event_mask |= select.POLLIN
    if writable:
        event_mask |= select.POLLOUT
    if error:
        event_mask |= select.POLLERR

    pollable = select.poll()
    pollable.register(fd, event_mask)

    if timeout:
        event_list = pollable.poll(long(timeout * 1000))
    else:
        event_list = pollable.poll()

    return bool(event_list)


问题


面经


文章

微信
公众号

扫码关注公众号