I’m writing an IRC bot in Python, due to the alpha nature of it, it will likely get unexpected errors and exit.
What’s the techniques that I can use to make the program run again?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can use
sys.exit()to tell that the program exited abnormally (generally, 1 is returned in case of error).Your Python script could look something like this:
You could call again
main()in case of error, but the program might not be in a state where it can work correctly again.It may be safer to launch the program in a new process instead.
So you could write a script which invokes the Python script, gets its return value when it finishes, and relaunches it if the return value is different from 0 (which is what
sys.exit()uses as return value by default).This may look something like this: