slytomcat added the comment:

Raymond, Serhiy, thanks for your opinions.

I agree that this method like empty, full, and qsize returns information that 
may be out-of-date in time of its usage.

But like those empty, full, and qsize it provides information that helps to 
make some decisions.

What I disagree that this information can be correctly estimated based on qsize 
and number of parallel consumers as there is no information what exactly 
consumers do at the moment. Such estimation will be absolutely useless for a 
decision making.

In the example (see 
https://github.com/slytomcat/cpython/commit/ea313986d86c083e81624fbc8a7ab6a75784e15d)
 we need to estimate the number of unfinished tasks and comparing it to the 
number of active threads we can decide: should we create a new thread or not. 
There is no reason to wait until all tasks done (via join) we need to make 
decision in working conditions.

Actually I've implemented this solution (Queue.unfinished + modified 
concurrent.futures.ThreadPoolExecutor) in my project (see 
https://github.com/slytomcat/yandex-disk-client) and it works perfectly: the 
number of working threads is increasing only on massive flow of tasks, while 
weak flow of tasks keeps low number of working threads.
And even when Queue.unfinished gives wrong (outdated) information, it can lead 
to creation one new thread that is not really required at the moment. That is 
not a big mistake, I suppose (comparing to creation all N threads during 
placing first N tasks in queue without considering the volume of concurrent 
tasks).

----------

_______________________________________
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