Jason Woodruff
Jason Woodruff

Reputation: 87

Another: Warning, too much iteration done before the next frame

When I run my script, I get this error:

[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute

This happens when I call a method in a class that is called class mgsApp(BoxLayout), that is, when I call the method from another class.

The method is this:

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

Then it reloads the list from a text file. It iterates through that list. Here is that method that does that. It is in the same class with listCleaner, which is the mgsApp class.

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

This is added to a listview, thus the line, self.the_mLv.adapter.data.extend(lItem). The user will select a item from the list and press a "Got!" button on top of a ActionBar, which is an ActionButton. Then a popup will ask the user if they are sure if they want to delete the item? When you press yes, you invoke a method in that Popup class called class itemToDelete(Popup): The method is this:

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

The line:

mSlReload = mgsApp() 
mSlReload.listCleaner()

Causes the error to occur. The error, too much iteration. It seems that I can't call anything within that mgsApp class. Even a simple print statement to the console causes this error. By the way here is my App class:

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

I tried to reproduce this error in another water down script, but It worked, Here is that script:

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

The script I'm working with is 1200 lines plus long, so showing it here would be not too feasible. I hope this is enough of information to maybe see where the problem is. Any help would be appreciated.

Upvotes: 1

Views: 2337

Answers (1)

Jason Woodruff
Jason Woodruff

Reputation: 87

The problem was in the `ActionBar' Here is my code, this is where it would be in the kv file, or in my case, in the '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 in the ActionOverflow was causing the Warning, too much iteration error that flooded the console. Commenting that out stopped that. Why it causes really is still to be determined. Just thought I would post this if someone runs into this same problem

Upvotes: 2

Related Questions