On Thu, Feb 24, 2011 at 9:43 AM, Iustin Pop <[email protected]> wrote:
> On Thu, Feb 24, 2011 at 09:07:16AM +0100, Rene Nussbaumer wrote:
>> On Wed, Feb 23, 2011 at 4:57 PM, Michael Hanselmann <[email protected]> 
>> wrote:
>> > Am 23. Februar 2011 10:41 schrieb René Nussbaumer <[email protected]>:
>> >> +  results = jex.GetResults()
>> >> +  bad_cnt = sum(1 for (success, _) in results if not success)
>> >
>> > Please use len(), not sum().
>>
>> Please make up your mind then :). Either you want me to use a
>> generator for memory optimization or your want me to use len(). Both
>> are not working together, because generators do not have a length.
>> Which make sense as a generator can generate an infinite amount of
>> data where a len wouldn't work on (hint: Fibonacci sequence to call a
>> well known example). So what do you want me to do?
>
> Hah:
>
>>>> len(i for i in range(5))
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: object of type 'generator' has no len()
>>>>
>
> I believe that hansmi was again trying to optimize things that not need
> optimization…

Interdiff:
diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py
index c8d4365..dcd0792 100644
--- a/lib/client/gnt_cluster.py
+++ b/lib/client/gnt_cluster.py
@@ -957,7 +957,7 @@ def _InstanceStart(opts, inst_list, start):
     jex.QueueJob(inst, op)

   results = jex.GetResults()
-  bad_cnt = sum(1 for (success, _) in results if not success)
+  bad_cnt = len([1 for (success, _) in results if not success])

   if bad_cnt == 0:
     ToStdout("All instances have been %s successfully", text_success)


René

Reply via email to