[Tutor] Finding out what causes the crash

François Granger francois.granger@free.fr
Tue Feb 4 08:13:01 2003


on 4/02/03 12:25, Charlie Clark at charlie@begeistert.org wrote:

> I've got a script which causes the Python binary to crash. Initial
> observations tell me it has something to do with a particular database
> insert but it is not always the same one and it does not always appear to
> be the same string.
> 
> I get the same problem using Python 2.1.1 on windows and Python 2.1.3
> 
> What is the best way to find out more about what's happening?

Keep a log with a simple log utils. Just before the faulty code, log the
parameters.

class logthis:
    def __init__(self, logfile):
        import time
        self.t = time.ctime
        self.logfile = logfile
        try:
            fp = file(self.logfile)
        except:
            fp = file(self.logfile, 'w')    # will creat the file if not
avail
        fp.close()
    
    def __call__(self, *args):
        t = self.t()
        l = []
        for item in args:
            l.append(str(item))
        file(self.logfile, 'a').write(t + '\t' + '\t'.join(l) + '\n')

At biggining of program:

L = logthis('toto.txt')

Then:

Params = list(things)
L(Params)

-- 
Le courrier est un moyen de communication. Les gens devraient
se poser des questions sur les implications politiques des choix (ou non
choix) de leurs outils et technologies. Pour des courriers propres :
<http://marc.herbert.free.fr/mail/> -- <http://minilien.com/?IXZneLoID0>