【问题标题】:Another: Warning, too much iteration done before the next frame另一个:警告,在下一帧之前完成了太多的迭代
【发布时间】:2018-02-19 20:07:27
【问题描述】:

当我运行我的脚本时,我得到了这个错误:

[CRITICAL] [Clock ] 警告,在下一帧之前完成了太多迭代。检查你的代码, 或者增加 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)。 用户将从列表中选择一个项目并按下“得到!”顶部的按钮 ActionBar,这是一个ActionButton。然后弹出窗口会询问用户是否是 确定他们是否要删除该项目?当你按下是时,你调用了一个方法 在那个Popup 类中调用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()

行:

mSlReload = mgsApp() 
mSlReload.listCleaner()

导致错误发生。错误,太多的迭代。看来我 不能在那个 mgsApp 类中调用任何东西。即使是简单的打印语句 到控制台会导致此错误。顺便说一下,这是我的 App 类:

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()

我试图在另一个淡化脚本中重现此错误,但它奏效了, 这是那个脚本:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.lang import Builder

Builder.load_string('''

<popuptest>:
    # POPUP test
    size_hint: .8, .47
    auto_dismiss: False
    title: "Popup Test"
    BoxLayout:
        orientation: "vertical"
        padding: 40
        spacing: 40  
        Button:
            text: "Print to console"
            height: 40
            width: 130
            size_hint: (None, None)
            pos_hint: {'center_x': 0.5}
            on_press: root.printMe()
        Label:
            text: " "
        Button:
            text: "Close"
            height: 40
            width: 80
            size_hint: (None, None)
            pos_hint: {'center_x': 0.5}
            on_release: root.dismiss()

<mgsApp>:
    canvas:
        Color:
            rgba: .200, .235, .235, 1
        Rectangle:
            pos: self.pos
            size: self.size
    orientation: "vertical"
    ActionBar:
        ActionView:
            use_seperator: True
            ActionPrevious:
                title: "Test App"
                with_previous: False            
            ActionButton:
                text: "Print to console"
                on_press: root.itemHandler()
            ActionButton:                
                text: "Open Popup"
                on_release: root.openPopup()
    Label:
        text: ' '
        text_size: self.size


''')

class popuptest(Popup):

    def printMe(self):
        #This should cause too much iteration!
        printing = mgsApp()
        printing.itemHandler()

class mgsApp(BoxLayout):

    def itemHandler(self):
        #print to the console
        print "Testing 123"

    def openPopup(self):
        popupWindow = popuptest()
        popupWindow.open()

class mgsAppApp(App):

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

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

我正在使用的脚本有 1200 行加长,所以在这里展示它不太可行。我希望这是足够的信息,也许可以看到问题出在哪里。任何帮助,将不胜感激。

【问题讨论】:

  • 你放在最后的代码重现了你的错误?
  • 您可能正在创建一个无限循环,例如,您可能正在修改一个属性来更改另一个属性,而这个属性更改为第一个属性,从而生成一个无限循环。
  • 我现在正在工作,但让我检查一下确切的 python 版本和 kivy 版本。该示例适用于我。

标签: python-2.7 kivy


【解决方案1】:

问题出在 `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)

ActionOverflow 中的#text_size: self.size 导致了充斥控制台的Warning, too much iteration 错误。评论出来就停止了。为什么它确实导致仍有待确定。只是想如果有人遇到同样的问题我会发布这个

【讨论】:

  • 您好,当我尝试使用弹出窗口时,我也收到了“警告,在下一帧之前完成了太多迭代”。我在标签中有 text_size: self.size ,将其注释掉,并且有效。谢谢!!!
  • @JBart 很高兴听到这个消息!
猜你喜欢
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
  • 2019-04-12
  • 1970-01-01
  • 2020-09-28
  • 1970-01-01
  • 2016-11-04
  • 1970-01-01
相关资源
最近更新 更多