Author vstinner
Recipients pablogsal, vstinner
Date 2019-06-07.11:00:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559905219.95.0.653226520734.issue36402@roundup.psfhosted.org>
In-reply-to
Content
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/__init__.py", line 2794 in run_in_subinterp
  File "/home/vstinner/prog/python/master/Lib/test/test_threading.py", 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 <solipsis@pitrou.net>
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.
History
Date User Action Args
2019-06-07 11:00:19vstinnersetrecipients: + vstinner, pablogsal
2019-06-07 11:00:19vstinnersetmessageid: <1559905219.95.0.653226520734.issue36402@roundup.psfhosted.org>
2019-06-07 11:00:19vstinnerlinkissue36402 messages
2019-06-07 11:00:19vstinnercreate