title: Why does sys.exit() not exit when called inside a thread in Python?
body: <p>I am confused as to why the following code snippet would not exit when called in the thread, but would exit when called in the main thread.</p>
  <pre><code>import sys, time
  from threading import Thread
  
  def testexit():
      time.sleep(5)
      sys.exit()
      print &quot;post thread exit&quot;
  
  t = Thread(target = testexit)
  t.start()
  t.join()
  print &quot;pre main exit, post thread exit&quot;
  sys.exit()
  print &quot;post main exit&quot;
  </code></pre>
  <p>The docs for <code>sys.exit()</code> state that the call should exit from Python. I can see from the output of this program that &quot;post thread exit&quot; is never printed, but the main thread just keeps on going even after the thread calls exit.</p>
  <p>Is a separate instance of the interpreter being created for each thread, and the call to <code>exit()</code> is just exiting that separate instance? If so, how does the threading implementation manage access to shared resources? What if I did want to exit the program from the thread (not that I actually want to, but just so I understand)?</p>