Python 函数拾取

    @staticmethod
    def recursive_dir(main_path, list_type="file"):
        '''
        递归的列出文件或目录,或所有
        输入:
            main_path:查询主目录
        输出:无
        '''
        lRet = []
        list_dirs = os.walk(main_path)
        for root, dirs, files in list_dirs:
            for d in dirs:
                if list_type in ("dir", "all"):
                    lRet.append(os.path.join(root, d))
            for f in files:
                if list_type in ("file","all"):
                    lRet.append(os.path.join(root, f))
        return lRet

    @staticmethod
    def remove_empty_dir(main_path):
        '''
        删除空目录
        输入:
            main_path:要删除的主目录
        输出:无
        '''
        files = CMisce.recursive_dir(main_path, "file")
        dirs = CMisce.recursive_dir(main_path, "dir")
        dir_no_delete = []
        for path in files:
            dir_no_delete.append(os.path.dirname(path))
        for dir in set(dirs) - set(dir_no_delete):
            try:os.remove(dir)
            except: pass


  File "daemon.py", line 207, in safe_sleep
    time.sleep(sleep_time)
IOError: [Errno 4] Interrupted function call

@staticmethod
    def safe_sleep(sleep_time):
        """
        多线程安全sleep函数, 异常:IOError: [Errno 4] Interrupted function call
        参数:无
        返回:无
        说明:在多线程中直接调用time.sleep会异常。
        """
        try:
            time.sleep(sleep_time)
        except IOError, e:
            print_yellow("Skip sleep exception")

解决:

你可能感兴趣的:(Python 函数拾取)