Python errno 模块,ENETDOWN 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用errno.ENETDOWN

项目:canopen-rpi    作者:bggardner    | 项目源码 | 文件源码
def recv(self):
        try:
            data = super().recv(Message.SIZE)
        except OSError as e:
            if e.errno == errno.ENETDOWN:
                raise BusDown
            raise
        res = ioctl(self, 0x8906, struct.pack("@LL", 0, 0))
        seconds, microseconds = struct.unpack("@LL", res)
        timestamp = seconds + microseconds / 1000000
        msg = Message.from_bytes(data)
        msg.timestamp = timestamp
        return msg
项目:GotoX    作者:SeaHOH    | 项目源码 | 文件源码
def get_listen_ip():
    listen_ip = []
    sock = None
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.connect(('8.8.8.8', 53))
        listen_ip.append(sock.getsockname()[0])
    except:
        pass
    finally:
        if sock:
            sock.close()
    sock = None
    try:
        sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
        sock.connect(('2001:4860:4860::8888', 53))
        listen_ip.append(sock.getsockname()[0].partition('%')[0])
    except:
        pass
    finally:
        if sock:
            sock.close()
    if listen_ip:
        return listen_ip
    else:
        import errno
        raise OSError(errno.ENETDOWN, '???????')
项目:pipypd    作者:stressfm    | 项目源码 | 文件源码
def main():
    global HOST, PORT, EOF, MAXTRIES
    global s, tries, loops
    try:
        s.connect((HOST, PORT))
        while True:
            # Measure timing using GPIO4
            risetime = RCtime(4)
            # Send to the connected socket
            # (as we're using UDP, we must
            # send separate messages)
            s.sendall('foo %s%s' % (loops, EOF))
            s.sendall('bar %s%s' % (risetime, EOF))
            # Advance counter
            loops = loops + 1
    except socket.error as err:
        errcode = err[0]
        if errcode==errno.ECONNREFUSED:
            print 'Connection refused by host!'
        elif errcode==errno.ENETDOWN:
            print 'No network connection!'
        elif errcode==errno.ENETUNREACH:
            print 'Network unreachable!'
        elif errcode==errno.ENETRESET:
            print 'Network dropped connection!'
        elif errcode==errno.ECONNRESET:
            print 'Connection reset by peer!'
        elif errcode==errno.EHOSTDOWN:
            print 'Host is down!'
        elif errcode==errno.EHOSTUNREACH:
            print 'No route to host!'
        else:
            print 'Caught: %s!' % err

        if tries >= MAXTRIES:
            GPIO.cleanup()
            s.close()
            print 'No connection. Exiting.'
        else:
            print 'Tried %i of %i times.\nWaiting %is...' % (tries, MAXTRIES, tries/10)
            time.sleep(tries/10)
            tries = tries + 1
            main()
    except KeyboardInterrupt:
        GPIO.cleanup()
        s.close()
        print '%i loops' % loops