另一个:警告,在下一帧之前完成了太多的迭代

时间:2018-02-19 20:07:27

标签: python-2.7 kivy

当我运行我的脚本时,我收到此错误:

[关键] [时钟]警告,在下一帧之前完成了太多的迭代。检查你的代码, 或者增加Clock.max_iteration属性

当我在名为class mgsApp(BoxLayout)的类中调用方法时会发生这种情况, 也就是说,当我从另一个类调用该方法时。

方法是:

def listCleaner(self):
    try:
        for mdw in lItem:
            self.the_mLv.adapter.data.remove(mdw)                
    except ValueError:
        pass
    #Reload list
    self.listLoader()

然后从文本文件重新加载列表。它迭代 通过该清单。这是那种方法。 它与listCleaner属于同一类,即 mgsApp上课。

def listLoader(self):
    mslFile = os.path.isfile(mgs.strip() + "mylist.txt")
    if mslFile == True:
        with open(mgs.strip() + "mylist.txt", "r") as info:
        try:
            global lItem
            lItem = [items.strip() for items in info]
            self.the_mLv.adapter.data.extend(lItem)
            info.close()
        except IndexError:
            pass
    elif mslFile == False:
        pass

这会添加到listview,即行self.the_mLv.adapter.data.extend(lItem)。 用户将从列表中选择一个项目并按下" Got!"顶部的按钮 ActionBarActionButton。然后弹出窗口将询问用户是否是 确定他们是否要删除该项目?按yes时,将调用方法 在名为Popup的{​​{1}}类中,方法如下:

class itemToDelete(Popup):

该行:

def yesToRemove(self):
    with open(mgs.strip() + "mylist.txt", "r") as mLst:
        remove = [itemSelected] #a global variable
        tempLst = [ ]
        for line in mLst:
            for iS in remove:
                if iS in line:
                    line = line.replace(iS, ' ')
                    line = line.strip()
            tempLst.append(line)
        mLst.close()

    #Writing back the changes to "mylist.txt"
    with open(mgs.strip() + "mylist.txt", "w") as lstWb:
        for line in tempLst:
            lstWb.write(line)
        lstWb.close()

    #Re-load shopping list
    #Got to find a workaround        
    mSlReload = mgsApp() 
    mSlReload.listCleaner()

    #Check filesize of "mylist.txt"
    mLfs = os.stat(mgs.strip() + "mylist.txt")
    mLActual = mLfs.st_size

    if mLActual > 1:
        pass
    else:        
        #Remove mylist.txt
        listDone = lstFinalRemove()
        listDone.open()

导致错误发生。错误,迭代太多。看来我 无法调用该mgsApp类中的任何内容。即使是简单的印刷声明 到控制台导致此错误。顺便说一句,这是我的App类:

mSlReload = mgsApp() 
mSlReload.listCleaner()

我试图在另一个水下脚本中重现此错误,但它有效, 这是脚本:

class mgsAppApp(App):

    def build(self):
        self.main_screen = mgsApp()
        return self.main_screen        

    def initilize_global_vars(self, *args):
        #This gives me a place on Android, to
        #write and store files to.
        global mgs
        root_folder = self.user_data_dir
        mgs = os.path.join(root_folder, ' ')

    def on_start(self):
        Clock.schedule_once(self.initilize_global_vars, -1)
        Clock.schedule_once(self.main_screen.accountChk, -1)
        Clock.schedule_once(self.main_screen.lastLst_global, -1)   

if __name__ == '__main__':
    mgsAppApp().run()

我正在使用的脚本是1200行加长,所以在这里显示它不太可行。我希望这些信息足以让我们看到问题所在。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

问题在于`ActionBar'这是我的代码,这是在哪里 它将在kv文件中,或者在我的情况下,在' Builder.load_string'中:

<mgsApp>:
    name: "mgs"
    the_mLv: id_mLv
    # https://stackoverflow.com/questions/29882870/
    # how-to-position-boxlayout-to-top-of-screen
    canvas:
        Color:
            rgba: .200, .235, .235, 1
        Rectangle:
            pos: self.pos
            size: self.size
    orientation: "vertical"
    ActionBar:
        ActionView:
            use_seperator: True
            ActionPrevious:
                title: "My Go Shopping"
                with_previous: False
                app_icon: "icon_tray.png"            
            ActionButton:
                text: "Got!"
                on_press: root.itemHandler()
            ActionButton:                
                text: "Refresh"
                on_release: root.listCleaner()
            ActionOverflow:
                ActionButton:
                    text: "New List"
                    #text_size: self.size
                    on_press: root.chkForNewList()
                ActionButton:
                    text: "Check Server"
                    #text_size: self.size
                    on_press: root.accountToServer()
                ActionButton:
                    text: "Logout"
                    #text_size: self.size
                    on_press: root.accountRemove()

    ListView:
        id: id_mLv
        adapter:
            ListAdapter(
            data=[ ],
            selection_mode="single",
            allow_empty_selection=True,
            cls=ListItemButton)
#text_size: self.size中的

ActionOverflow导致充斥控制台的Warning, too much iteration错误。评论说停止了这一点。究其原因还有待确定。只是想如果有人遇到同样的问题我会发布这个