示例#1
0
 def average(self):
     if not len(self.samples):
         logger.error("average called before any data could get in")
         return 0
     # Copy deque content by using list() copy constructor
     #   to avoid: RuntimeError: deque mutated during iteration
     samples = [sum(sample.values()) for sample in list(self.samples)]
     return sum(samples) / float(len(samples))
示例#2
0
def getwb(address):
    try:
        return WiiboardThreaded(address)
    except Exception as e:
        logger.error("Could not connect to %s : %s", address, str(e))
        # bluetooth.btcommon.BluetoothError: (113, 'No route to host')
        #   interface error most probably `hciattach` init error
        # bluetooth.btcommon.BluetoothError: (112, 'Host is down')
        #   balance out of reach
        # str(e)[1:-1].split(', ')
    return None
示例#3
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except Exception as e:
         logger.error("%s error %s", func.__name__, e)
         return 0