diff options
author | Hal Canary <halcanary@google.com> | 2018-02-05 11:36:25 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-05 17:06:16 +0000 |
commit | 5f73c217cc110f28ecc664643899808004239a02 (patch) | |
tree | eaa664089dc81ea90880410d510dc49b3a3c0c34 /tools | |
parent | 11bdbe00133d6c3b89034e2bff08ec0962a10c0d (diff) |
SkQP: use multiprocessing over threading
BUG=skia:7579
NOTRY=true
Change-Id: I4c7d2331e88171943f724592eb1481a5ea41b0ba
Reviewed-on: https://skia-review.googlesource.com/103700
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/skqp/download_model | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/tools/skqp/download_model b/tools/skqp/download_model index 90a46256f6..c18ebfa428 100755 --- a/tools/skqp/download_model +++ b/tools/skqp/download_model @@ -5,10 +5,10 @@ # found in the LICENSE file. import hashlib +import multiprocessing import os import shutil import sys -import threading import tempfile import urllib2 @@ -46,7 +46,6 @@ def main(): os.chdir(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'platform_tools', 'android', 'apps', 'skqp', 'src', 'main', 'assets')) - sys.stderr.write('\n 0 / ???? ') file_list_file = tmp('files_') with open('files.checksum', 'r') as f: md5 = f.read().strip() @@ -57,18 +56,12 @@ def main(): for line in f: md5, path = line.strip().split(';', 1) records.append((md5, path)) - threads = set() - sys.stderr.write('\r 0 / %d ' % len(records)) - for i, record in enumerate(records): - t = threading.Thread(target=download, args=record) - t.start() - threads.add(t) - left = -1 - while left != 0: - count = sum(1 for t in threading.enumerate() if t in threads) - if left != count: - left = count - sys.stderr.write('\r %4d / %d ' % (len(records) - left, len(records))) + sys.stderr.write('Downloading %d files.\n' % len(records)) + pool = multiprocessing.Pool(processes=multiprocessing.cpu_count() * 2) + for record in records: + pool.apply_async(download, record, callback=lambda x: sys.stderr.write('.')) + pool.close() + pool.join() sys.stderr.write('\n') if __name__ == '__main__': |