Generate rating calculation promises in list comprehension

This commit is contained in:
Kristóf Tóth 2018-04-28 23:32:08 +02:00
parent 649b55f84f
commit d5bbe5139d

7
cli.py
View File

@ -41,11 +41,10 @@ class Cli:
self.args = ap.parse_args() self.args = ap.parse_args()
def calculate_ratings(self): def calculate_ratings(self):
ratings = []
with Pool(processes=cpu_count()) as pool: with Pool(processes=cpu_count()) as pool:
for image in self.args.images: ratings = [(image, pool.apply_async(self.calculate_rating,
ratings.append((image, pool.apply_async(self.calculate_rating, (image, self.args.method)))
(image, self.args.method)))) for image in self.args.images]
self.image_ratings = {image: promise.get() for image, promise in ratings} self.image_ratings = {image: promise.get() for image, promise in ratings}
@staticmethod @staticmethod