Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:55:30+00:00 2026-06-18T05:55:30+00:00

probably a simple question as I fairly new to python and programming in general

  • 0

probably a simple question as I fairly new to python and programming in general but I am currently working on improving a program of mine and can’t figure out how to keep the program going if an exception is caught. Maybe I am looking at it the wrong way but for example I have something along these lines:

    self.thread = threading.Thread(target=self.run)
    self.thread.setDaemon(True)
    self.thread.start()

    def run(self):
        logging.info("Starting Awesome Program") 
        try:
            while 1:
                awesome_program(self)
    except:
        logging.exception('Got exception on main handler')
        OnError(self)

    def OnError(self):
        self.Destroy()

Obviously I am currently just killing the program when an error is reached. awesome_program is basically using pyodbc to connect and run queries on a remote database. The problem arises when connection is lost. If I don’t catch the exceptions the program just freezes so I set it up as it is above which kills the program but this is not always ideal if no one is around to manually restart it. Is there an easy way to either keep the program running or restert it. Feel free to berate me for incorrect syntax or poor programming skills. I am trying to teach myself and am still very much a novice and there is plenty I don’t understand or am probably not doing correctly. I can post more of the code if needed. I wasn’t sure how much to post without being overwhelming.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:55:31+00:00Added an answer on June 18, 2026 at 5:55 am

    Catch the exception within the loop, and continue, even if an exception is caught.

    def run(self):
            logging.info("Starting Awesome Program") 
            while 1:
                try:
                    awesome_program(self)
                except:
                    logging.exception('Got exception on main handler')
                    OnError(self)
    

    BTW:

    • Your indentation seems messed up.
    • I’d prefer while True. Python has bool type, unlike C, so when a bool is expected – give while a bool.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a fairly simple question but I can't seem to make sense of why
This is probably a fairly simple question, but I can't seem to figure it
I have what is probably a very simple question, but I'm fairly new to
This is probably a simple question but I can't seem to figure out how
This is probably a very simple question so please forgive my ignorance, but can
I think this question is probably fairly simple, but I've been searching around and
This is a very simple (and probably dumb) question, but I can't seem to
I'm very new to Python, so sorry for the probably simple question. (Although, I
Probably simple question, but I can't find solution. How to prevent jQuery-dependent SomeClassName class
Hey guys, sorry for this probably fairly simple question but I'm starting to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.