]> granicus.if.org Git - python/commit
bpo-36402: Fix threading._shutdown() race condition (GH-13948)
authorVictor Stinner <vstinner@redhat.com>
Wed, 12 Jun 2019 23:30:17 +0000 (01:30 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2019 23:30:17 +0000 (01:30 +0200)
commit468e5fec8a2f534f1685d59da3ca4fad425c38dd
treeab031e145d86984c0a6236053e8768207e3b2fb2
parentb4c7defe58695a6670a8fdeaef67a638bbb47e42
bpo-36402: Fix threading._shutdown() race condition (GH-13948)

Fix a race condition at Python shutdown when waiting for threads.
Wait until the Python thread state of all non-daemon threads get
deleted (join all non-daemon threads), rather than just wait until
Python threads complete.

* Add threading._shutdown_locks: set of Thread._tstate_lock locks
  of non-daemon threads used by _shutdown() to wait until all Python
  thread states get deleted. See Thread._set_tstate_lock().
* Add also threading._shutdown_locks_lock to protect access to
  threading._shutdown_locks.
* Add test_finalization_shutdown() test.
Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS.d/next/Library/2019-06-11-00-35-02.bpo-36402.b0IJVp.rst [new file with mode: 0644]