New submission from slytomcat:

Class queue.Queue control the number of unfinished tasks via method 
task_done(). But it is only possible to get the information about all task done 
(via join() method). 
I'm sure that exposing the number of unfinished tasks (unfinished_tasks class 
variable) can be very useful in many situations when you need more control over 
the process.

But it is not good idea to provide write access to this internal variable (as 
it controls internal queue class status). Better way - provide RO access via 
class method like qsize or empty. It can be look like this:

    def unfinished(self):
        return self.unfinished_tasks


One example of this method usage: there is not optimal function 
_adjust_thread_count in concurrent.futures.ThreadPoolExecutor with following 
comment: 
    # TODO(bquinlan): Should avoid creating new threads if there are more
    # idle threads than items in the work queue.

It can be easily done with following condition:

    if self._work_queue.unfinished() <= len(self._threads):
        return

----------
components: Library (Lib)
messages: 288189
nosy: rhettinger, slytomcat
priority: normal
severity: normal
status: open
title: More informative Queue class: new method that returns number of 
unfinished tasks
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29603>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to