0

I’ve developed a python code which revolves around a main() which spawns a number of threads, each of which watch a folder for new data and when it arrives, so something with it. This code runs forever until the user stops it.

In the main() there is lots of error trapping using try/except and, if an error occurs, sys.exit() is called. Similarly, if the user issues Ctrl+C the same happens. All this works fine.

The trouble I’m having, and it’s admittedly a gap in my knowledge, is that if a error is throw in one of the threads (any thread), how can I get it to kill the main() and hence the whole program? If I use sys.exit() in the thread it just kills that thread, not the main()/whole program.

Any thoughts would be helpful.

Mark
  • 1,277
  • 3
  • 13
  • 27
  • have you tried to use the correctness of the folder or downloaded files? – KruII Mar 23 '22 at 16:42
  • `sys.exit()` exits entire process, regardless of what thread calls it. The issue seems to be elsewhere. Do you perhaps use multiple processes instead of threads? – freakish Mar 23 '22 at 16:45
  • How are you spawning the threads? using [Popen](https://stackoverflow.com/a/12605520/6372042) may help you our here. – James Burgess Mar 23 '22 at 16:46
  • @freakish - I’m definitely using multiple threads, not processes. They are started in the main() using x = threading.Thread(target=thread_function) x.start() – Mark Mar 23 '22 at 19:37

0 Answers0