]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-37193: remove thread objects which finished process its request (GH-13893)
authorMARUYAMA Norihiro <norihiro.maruyama@gmail.com>
Sun, 1 Nov 2020 23:51:04 +0000 (08:51 +0900)
committerGitHub <noreply@github.com>
Sun, 1 Nov 2020 23:51:04 +0000 (18:51 -0500)
commitc41559021213cfc9dc62a83fc63306b3bdc3e64b
tree2a8974f08a5fa31aa57d336b29f01dddd5df164c
parente662c398d87f136497f8ec672e83657ae3a599e0
bpo-37193: remove thread objects which finished process its request (GH-13893)

* bpo-37193: remove the thread which finished process request from threads list

* rename variable t to thread.

* don't remove thread from list if it is daemon.

* use lock to protect self._threads.

* use finally block in case of exception from shutdown_request().

* check "not thread.daemon" before lock to avoid holding the lock if it's unnecessary.

* fix the place of _threads_lock.

* separate code to remove a current thread into a function.

* check ValueError when removing thread.

* fix wrong code which all instance shared same lock.

* Extract thread management into a _Threads class to encapsulate atomic operations and separate concerns.

* Replace multiple references of 'block_on_close' with one, avoiding the possibility that 'block_on_close' could change during the course of processing requests. Now, there's exactly one _threads object with behavior fixed for the duration.

* Add docstrings to private classes.

* Add test to ensure that a ThreadingTCPServer can be closed without serving any requests.

* Use _NoThreads as the default value. Fixes AttributeError when server is closed without serving any requests.

* Add blurb

* Add test capturing failure.

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/socketserver.py
Lib/test/test_socketserver.py
Misc/NEWS.d/next/Library/2020-06-12-21-23-20.bpo-37193.wJximU.rst [new file with mode: 0644]