[3.8] bpo-37193: remove thread objects which finished process its request (GH-13893) #23088
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
(cherry picked from commit c415590)
Co-authored-by: MARUYAMA Norihiro norihiro.maruyama@gmail.com
https://bugs.python.org/issue37193