欧斯波本一定时间后返回空

2024-03-29 12:44:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的项目中有一个函数,它返回/tmp分区大小和可用的分区数量,有时它工作得很好,但在一段时间之后欧斯波本函数返回空文件对象,函数将抛出错误。下面是我的代码。你知道吗

def get_temp_dir_size():
    """ the function returns the tmp partetion size and avilable size"""
    data = [0,0]
    with os.popen('df -h /tmp') as f:
        f_data = f.readlines()
        try:
            data = re.findall(r'(\d*\.*\d+)M',f_data[-1])
        except:
            log.exception("*** Some error occured")
            log.debug("*** data in the file : {0}".format(f_data))
    return {'flashSize':data[0],'flashFree':data[1]}

以下是错误

Traceback (most recent call last):
  File "/etc/dnp/dnp_utils.py", line 614, in get_temp_dir_size
    data = re.findall(r'(\d*\.*\d+)M',f_data[-1])
IndexError: list index out of range
2018-02-15 05:51:36,626 [DEBUG](           dnp_utils: 617): *** data in the file : []

Tags: the函数inrelogdatasizeget