Why are the methods sys.exit(), exit(), raise SystemExit not working? Why are the methods sys.exit(), exit(), raise SystemExit not working? multithreading multithreading

Why are the methods sys.exit(), exit(), raise SystemExit not working?


The problem is that all sys.exit() does is raise SystemExit. Since this happens in a worker thread, the effect is to stop that thread (exceptions don't propagate across threads).

You could trying signalling to the main thread that the script needs to terminate, either though some mechanism of your own, or by calling thread.interrupt_main().

For a sledgehammer approach, call os._exit().


You can just raise SystemExit but that seems really harsh. Maybe some means of co-operative threading would work (ie: a queue with a sentinel)