]> granicus.if.org Git - python/commit
bpo-24882: Let ThreadPoolExecutor reuse idle threads before creating new thread ...
authorSean <iUnknwn@users.noreply.github.com>
Wed, 22 May 2019 21:29:58 +0000 (14:29 -0700)
committerAntoine Pitrou <antoine@python.org>
Wed, 22 May 2019 21:29:58 +0000 (23:29 +0200)
commit904e34d4e6b6007986dcc585d5c553ee8ae06f95
treeb2861de182ad8f0666f670b1f79e51a9d8ba1638
parent2a3a2ece502c05ea33c95dd0db497189e0354bfd
bpo-24882: Let ThreadPoolExecutor reuse idle threads before creating new thread (#6375)

* Fixes issue 24882

* Add news file entry for change.

* Change test_concurrent_futures.ThreadPoolShutdownTest

Adjust the shutdown test so that, after submitting three jobs
to the executor, the test checks for less than three threads,
instead of looking for exactly three threads.

If idle threads are being recycled properly, then we should have
less than three threads.

* Switched idle count to semaphor, Updated tests

As suggested by reviewer tomMoral, swapped lock-protected counter
with a semaphore to track the number of unused threads.

Adjusted test_threads_terminate to wait for completiton of the
previous future before submitting a new one (and checking the
number of threads used).

Also added a new test to confirm the thread pool can be saturated.

* Updates tests as requested by pitrou.

* Correct minor whitespace error.

* Make test_saturation faster
Lib/concurrent/futures/thread.py
Lib/test/test_concurrent_futures.py
Misc/NEWS.d/next/Library/2018-04-04-14-54-30.bpo-24882.urybpa.rst [new file with mode: 0644]