From 998d7741951c68b194eb9fab02509024bf60949e Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 13 Jun 2018 21:37:46 +0200 Subject: [PATCH] Fixed #29492 -- Improved compilemessages speed --- .../management/commands/compilemessages.py | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py index 77dd0f085c..0934874662 100644 --- a/django/core/management/commands/compilemessages.py +++ b/django/core/management/commands/compilemessages.py @@ -1,4 +1,5 @@ import codecs +import concurrent.futures import glob import os @@ -106,35 +107,41 @@ class Command(BaseCommand): """ Locations is a list of tuples: [(directory, file), ...] """ - for i, (dirpath, f) in enumerate(locations): - if self.verbosity > 0: - self.stdout.write('processing file %s in %s\n' % (f, dirpath)) - po_path = os.path.join(dirpath, f) - if has_bom(po_path): - self.stderr.write( - 'The %s file has a BOM (Byte Order Mark). Django only ' - 'supports .po files encoded in UTF-8 and without any BOM.' % po_path - ) - self.has_errors = True - continue - base_path = os.path.splitext(po_path)[0] + with concurrent.futures.ThreadPoolExecutor() as executor: + futures = [] + for i, (dirpath, f) in enumerate(locations): + if self.verbosity > 0: + self.stdout.write('processing file %s in %s\n' % (f, dirpath)) + po_path = os.path.join(dirpath, f) + if has_bom(po_path): + self.stderr.write( + 'The %s file has a BOM (Byte Order Mark). Django only ' + 'supports .po files encoded in UTF-8 and without any BOM.' % po_path + ) + self.has_errors = True + continue + base_path = os.path.splitext(po_path)[0] - # Check writability on first location - if i == 0 and not is_writable(base_path + '.mo'): - self.stderr.write( - 'The po files under %s are in a seemingly not writable location. ' - 'mo files will not be updated/created.' % dirpath - ) - self.has_errors = True - return + # Check writability on first location + if i == 0 and not is_writable(base_path + '.mo'): + self.stderr.write( + 'The po files under %s are in a seemingly not writable location. ' + 'mo files will not be updated/created.' % dirpath + ) + self.has_errors = True + return - args = [self.program] + self.program_options + [ - '-o', base_path + '.mo', base_path + '.po' - ] - output, errors, status = popen_wrapper(args) - if status: - if errors: - self.stderr.write('Execution of %s failed: %s.' % (self.program, errors)) - else: - self.stderr.write('Execution of %s failed.' % self.program) - self.has_errors = True + args = [self.program] + self.program_options + [ + '-o', base_path + '.mo', base_path + '.po' + ] + futures.append(executor.submit(popen_wrapper, args)) + + for future in concurrent.futures.as_completed(futures): + output, errors, status = future.result() + if status: + if self.verbosity > 0: + if errors: + self.stderr.write("Execution of %s failed: %s" % (self.program, errors)) + else: + self.stderr.write("Execution of %s failed" % self.program) + self.has_errors = True