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>
This commit is contained in:
parent
11bdbe0013
commit
5f73c217cc
@ -5,10 +5,10 @@
|
|||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import threading
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
@ -46,7 +46,6 @@ def main():
|
|||||||
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
||||||
'platform_tools', 'android', 'apps', 'skqp', 'src',
|
'platform_tools', 'android', 'apps', 'skqp', 'src',
|
||||||
'main', 'assets'))
|
'main', 'assets'))
|
||||||
sys.stderr.write('\n 0 / ???? ')
|
|
||||||
file_list_file = tmp('files_')
|
file_list_file = tmp('files_')
|
||||||
with open('files.checksum', 'r') as f:
|
with open('files.checksum', 'r') as f:
|
||||||
md5 = f.read().strip()
|
md5 = f.read().strip()
|
||||||
@ -57,18 +56,12 @@ def main():
|
|||||||
for line in f:
|
for line in f:
|
||||||
md5, path = line.strip().split(';', 1)
|
md5, path = line.strip().split(';', 1)
|
||||||
records.append((md5, path))
|
records.append((md5, path))
|
||||||
threads = set()
|
sys.stderr.write('Downloading %d files.\n' % len(records))
|
||||||
sys.stderr.write('\r 0 / %d ' % len(records))
|
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count() * 2)
|
||||||
for i, record in enumerate(records):
|
for record in records:
|
||||||
t = threading.Thread(target=download, args=record)
|
pool.apply_async(download, record, callback=lambda x: sys.stderr.write('.'))
|
||||||
t.start()
|
pool.close()
|
||||||
threads.add(t)
|
pool.join()
|
||||||
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('\n')
|
sys.stderr.write('\n')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user