0

I have written a "small" python service that grew too much, and from time to time, some exceptions happen (generally in a thread, or inside an async function). The main program keeps working, but not working right.

I am aware that the proper thing to do is to find where the exceptions happen (mostly caused by irregular data) and try to catch these exceptions, but I am in the middle of another project, and just don't have the time for it.

Is there a simple way, like, maybe an argument in python that closes the program when any exception occurs? Or perhaps a systemctl way to restart when an error occurs? (I have the Restart=always on my service file, but as I mentioned, the main program is working fine).

Thank you.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • This could help you: https://stackoverflow.com/questions/49663124/cause-python-to-exit-if-any-thread-has-an-exception – Károly Szabó Aug 29 '23 at 14:07
  • The fact there's exception thrown does not mean you must catch it. If you do not plan/need to have any error handling or recovery just let it bubble up and it will terminate your program – Marcin Orlowski Aug 29 '23 at 14:08
  • Can you give more details about the frameworks you are using? As said above, exceptions should bubble up and crash (terminate) your application as the default behavior. – Juliano Negri Aug 29 '23 at 18:33
  • @JulianoNegri it's a network service that receives raw codes and process them (really ancient stuff) and unfortunately those messages don't even have checksum, so when I receive a "broken" message, it breaks something somewhere. Rewrite the whole service the "right" way will take a long time that I don't have right now. – Guilherme Richter Aug 29 '23 at 19:17
  • If I understood: you can't handle your exceptions nor configure the system for not handling exceptions either... I see no shortcut – Juliano Negri Aug 30 '23 at 21:11

0 Answers0