Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The root difference here is actually unrelated to both signals and atexit, but rather a change in the behavior of <code>sys.exit</code>.</p> <p>Before around 2.6.5, <code>sys.exit</code> (more accurately, SystemExit being caught at the top level) would cause the interpreter to exit; if threads were still running, they'd be terminated, just as with POSIX threads.</p> <p>Around 2.6.5, the behavior changed: the effect of <code>sys.exit</code> is now essentially the same as returning from the main function of the program. When you do <em>that</em>--in both versions--the interpreter waits for all threads to be joined before exiting.</p> <p>The relevant change is that <code>Py_Finalize</code> now calls <code>wait_for_thread_shutdown()</code> near the top, where it didn't before.</p> <p>This behavioral change seems incorrect, primarily because it no longer functions as documented, which is simply: "Exit from Python." The practical effect is no longer to exit from Python, but simply to exit the thread. (As a side note, <code>sys.exit</code> has never exited Python when called from another thread, but that obscure divergance from documented behavior doesn't justify a much bigger one.)</p> <p>I can see the appeal of the new behavior: rather than two ways to exit the main thread ("exit and wait for threads" and "exit immediately"), there's only one, as sys.exit is essentially identical to simply returning from the top function. However, it's a breaking change and diverges from documented behavior, which far outweighs that.</p> <p>Because of this change, after <code>sys.exit</code> from the signal handler above, the interpreter sits around waiting for threads to exit and then runs <code>atexit</code> handlers after they do. Since it's the handler itself that tells the threads to exit, the result is a deadlock.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload