Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concurrent.futures.ThreadPoolExecutor: tasks in queue not marked as done #72836

Open
pyfm mannequin opened this issue Nov 9, 2016 · 1 comment
Open

concurrent.futures.ThreadPoolExecutor: tasks in queue not marked as done #72836

pyfm mannequin opened this issue Nov 9, 2016 · 1 comment
Labels
topic-multiprocessing type-bug An unexpected behavior, bug, or error

Comments

@pyfm
Copy link
Mannequin

pyfm mannequin commented Nov 9, 2016

BPO 28650
Files
  • thread.py.patch: Proposal of a patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2016-11-09.16:05:49.685>
    labels = ['type-bug']
    title = 'concurrent.futures.ThreadPoolExecutor: tasks in queue not marked as done'
    updated_at = <Date 2016-11-09.16:05:49.685>
    user = 'https://bugs.python.org/pyfm'

    bugs.python.org fields:

    activity = <Date 2016-11-09.16:05:49.685>
    actor = 'pyfm'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2016-11-09.16:05:49.685>
    creator = 'pyfm'
    dependencies = []
    files = ['45409']
    hgrepos = []
    issue_num = 28650
    keywords = ['patch']
    message_count = 1.0
    messages = ['280410']
    nosy_count = 1.0
    nosy_names = ['pyfm']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28650'
    versions = ['Python 3.5', 'Python 3.6']

    @pyfm
    Copy link
    Mannequin Author

    pyfm mannequin commented Nov 9, 2016

    Hi,

    I just realized that the ThreadPoolExecutor's workers do not call task_done() on the work_queue from which they took their task.
    Or is there a reason for not calling task_done that I am missing?

    Calling task_done decrements the queue's unfinished_tasks counter which could be used to improve the reuse of idle threads (see bquinlan's comment, Lib/concurrent/futures/thread.py:l124).

    I am thinking of something like
    if self._work_queue.unfinished_tasks > len(self._threads) and len(self._threads) < self._max_workers:

    One could still construct cases in which threads are created unnecessarily but it should improve the situation in most cases.

    (proposed patch is based on Python-3.6.0b3)

    @pyfm pyfm mannequin added the type-bug An unexpected behavior, bug, or error label Nov 9, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-multiprocessing type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Status: No status
    Development

    No branches or pull requests

    1 participant