This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients pablogsal, vstinner
Date 2019-06-07.11:00:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I wrote PR 13889: with this change, I can easily reproduce the crash on Linux:

$ ./python -m test test_threading -m test_threads_join_2 -F
Run tests sequentially
0:00:00 load avg: 0.51 [  1] test_threading
Fatal Python error: Py_EndInterpreter: not the last thread

Current thread 0x00007f84ad74d740 (most recent call first):
  File "/home/vstinner/prog/python/master/Lib/test/support/", line 2794 in run_in_subinterp
  File "/home/vstinner/prog/python/master/Lib/test/", line 923 in test_threads_join_2

Py_EndInterpreter() calls wait_for_thread_shutdown() to wait until threading._shutdown() completes.

When the assertion fails, threading.enumerate() only contains the main thread: the spawned thread is already gone. But the assertion fails, which means that the Python thread state of the thread (which looks to be completed) is still around.

This unit test comes from bpo-18808:

commit 7b4769937fb612d576b6829c3b834f3dd31752f1
Author: Antoine Pitrou <>
Date:   Sat Sep 7 23:38:37 2013 +0200

    Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
    This prevents unpredictable aborts in Py_EndInterpreter() when some non-daemon threads are still running.
Date User Action Args
2019-06-07 11:00:19vstinnersetrecipients: + vstinner, pablogsal
2019-06-07 11:00:19vstinnersetmessageid: <>
2019-06-07 11:00:19vstinnerlinkissue36402 messages
2019-06-07 11:00:19vstinnercreate