Message288189
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 |
|
Date |
User |
Action |
Args |
2017-02-20 09:12:24 | slytomcat | set | recipients:
+ slytomcat, rhettinger |
2017-02-20 09:12:24 | slytomcat | set | messageid: <1487581944.26.0.570957700938.issue29603@psf.upfronthosting.co.za> |
2017-02-20 09:12:24 | slytomcat | link | issue29603 messages |
2017-02-20 09:12:23 | slytomcat | create | |
|