#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Questioner's home
    Posts
    89
    Rep Power
    12

    Looping without interruption


    Hi guys, Im writing a tiny program that keeps looping and process reports until its interrupted by keyboard input only, errors (syntax, exceptions) occured in the process of the report will be trapped, logged, displayed and move on to next one.

    Now my problem is, my program only traps error occasionally, sometimes it doesnt work, when error happens it just report the error (displayed by my program instead of the usual error traceback we got while developing) and then stops looping, this is bad, its supposed to process reports while i was sleeping, so i cant constantly monitor the process and restart my program if stopped.

    my code roughly :

    Code:
    def roll():
        while 1:
            get report queued in db
            if found report:
                try:
                    process report
                except: #this should trap all errors right?
                    display error message
                    log error
    
    try:
       roll()
    except KeyboardInterrupt:
        print "Stopped"
    Thanks in advance.
    What can change the nature of a man?
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Do you mean
    Code:
    try:
        some code
    except Exception, inst:
        print inst
    ?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Questioner's home
    Posts
    89
    Rep Power
    12
    I prefer more detailed error report, so Im using traceback.format_exception(), but thats not my main concern, my problem is when exception happens, sometimes my program stopped looping after printing the error report.
    What can change the nature of a man?
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by Questioner
    I prefer more detailed error report, so Im using traceback.format_exception(), but thats not my main concern, my problem is when exception happens, sometimes my program stopped looping after printing the error report.
    Hey Q, try something like this. I can't test it right now but its more

    Code:
    while True:
        try:
            print 'some code here...'
        except KeyboardInterrupt:
            print '\nGoodbye...'
        except:
            pass
    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo