[New-bugs-announce] [issue44188] ThreadPoolExecutor unbalanced semaphore count

Bennie Swart report at bugs.python.org
Thu May 20 07:51:36 EDT 2021

New submission from Bennie Swart <bennieswart at gmail.com>:

The concurrent.futures.ThreadPoolExecutor class, which is the default asyncio executor, introduced the _idle_semaphore field in version 3.8 in order to track idle threads so they can be reused before increasing the pool size unnecessarily.
This semaphore counter becomes unbalanced when the thread pool is over-saturated, as can be seen in the file provided. This is due to workers always incrementing the count after finishing a job, whereas the executor only decrements the count if it is already greater than 0.
This seems to be a logic bug unrelated to the running environment and introduced since python 3.8.

components: asyncio
files: bug.py
messages: 394017
nosy: asvetlov, bennieswart, yselivanov
priority: normal
severity: normal
status: open
title: ThreadPoolExecutor unbalanced semaphore count
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file50054/bug.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list