Hello!
Today I ran against the fact, that sys.exit()
called from a child-thread does not kill the main process. I did not know this before, and this is okay, but I needed long time to realize this. It would have saved much much time, if sys.exit(msg)
would have printed msg
to stderr
. But it did not.
It turned out that it wasn't a real bug in my application; it called sys.exit(msg)
with a meaningful error in a volitional way -- but I just could not see this.
In the docs for sys.exit()
it is stated:
"[...] any other object is printed to sys.stderr
and results in an exit code of 1"
This is not true for a call from a child-thread, where sys.exit()
obviously behaves as thread.exit()
:
"Raise the SystemExit exception. When not caught, this will cause the thread to exit silently"
I think when a programmer wants sys.exit(msg)
to print an error message, then this should just be printed -- independent of the place from where it is called. Why not? I currently don't see any reason. At least there should be a hint in the docs for sys.exit()
that the message is not printed from threads.
What do you think? Why are error messages concealed from threads? Does this make sense?
Best regards,
Jan-Philip Gehrcke