[Tkinter-discuss] Re: pb with tcl / tk under win2000

stewart at midtoad.homelinux.org stewart at midtoad.homelinux.org
Wed Oct 13 18:25:11 CEST 2004


hi Francesco:

I tried your sample app, but added one line so there'd be a slight delay between
ticks. 

    def tickerThread(self):
        while(1):
            time.sleep(1)
            self.l.bell()

I also added a pack command to your init statement so your label would show up:
class Ticker:
    def __init__(self):
        self.l = Label(text="W")
        self.l.pack()

I'm also running Win2k, like you, and a 'stock' version of Tkinter which came
with my Python 2.3.  When I run your sample, Windows Task Manager reports a
rock-steady memory usage by Python.exe of 4660 kb over a 5-minute period.

I suppose this doesn't prove anything of help to you, but it indicates to me
that the stock version of Tkinter doesn't have a problem with memory
consumption.   Of course, if I understood you correctly, your problem with the
stock version was not memory consumption, but stability of the app. Is that correct?

I wonder if recompiling Tkinter is the right approach. Perhaps all you've done
is fix a symptom, rather than a problem.  I wonder if it might not be fruitful
to do more investigation as to why your app is crashing.  Could you add some
debug features so that information is written regularly to a log file that you
can analyse after the app crashes?  I use a similar approach, with the following
methods defined:

    def open_debug(self):
        '''Open a debug log file for writing.
           Flush the contents of it if it already exists.
           this method is called on app initialisation'''
        try:
            self.logFile = open(self.logName, 'w+')
        except:
            cantopen(logName)

    def close_debug(self):
        '''Close the debug log file and truncate it to zero length. 
           If we find a debug file with a non-zero length, it means that
           our app didn't close properly last time, and we will
           have to delete it manually.'''
        self.logFile.flush()
        self.logFile.truncate(0)
        self.logFile.close()

    def set_debug(self, mode):
        '''turn on debug mode'''
        if mode == 'Turn debug on':
            self.debug = 1
            self.ask_debug()
        elif mode == 'Turn debug off': 
            self.debug = 0
            self.ask_debug()
        else:
            self.view_debug()

    def clear_debug(self):
        '''turn off debug mode'''
        self.debug = 0
        self.ask_debug()
           
    def ask_debug(self):
        '''display debug mode'''
        statusDebug = ['off','on']
        showinfo(title='Debug Status', 
                message='Debug is now ' +statusDebug[self.debug])
        
    def write_debug(self, msg=''):
        '''write to a debug file. 
        Assume it is opened when the app starts (see further above), 
        and that it will be closed when the app ends (see self.end).'''
        self.logFile.write(msg+'\n')
        self.logFile.flush()

    def view_debug(self):
        '''display the contents of the debug file'''
        #showFile is an easygui method
        s = showFile(self.logName)
        s.show()
        #showFile.show(fid)

When I want to log something, I use this command:
if self.debug: self.write_debug('in function ' +fcnName +': some status message')

note that in the write_debug method, I call flush() to ensure that the log
message is immediately written to file, so that if the app crashes, I have as
much information as possible for later debugging.   Also note that my app's quit
command calls close_debug() to delete the log file upon normal termination.

Since debugging messages can cause the debug log to grow rapidly, I initiate my
app with debug turned off.  I have a menu item to turn it on and off:

        menuBar.addcascademenu('Options', 'Debug',
                                'Set debug mode',
traverseSpec = 'z', tearoff = 1, font=self.font)
        for mode in ('Turn debug on', 'Turn debug off', 'View debug file'):
            menuBar.addmenuitem('Debug', 'command', mode,
                                command = lambda self=self, mode=mode:
self.set_debug(mode),
                                font=self.font,
                                label = mode)

        ''' optionsDebugCmds = {
            'Turn debug on': 'self.set_debug',
            'Turn debug off': 'self.clear_debug',
            'View debug file': 'self.view_debug'} '''


hope this helps!

cheers
Stewart



More information about the Tkinter-discuss mailing list