-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
executable file
·54 lines (38 loc) · 1.17 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import glob
from sys import argv, stdout
from multiprocessing.pool import ThreadPool
import subprocess
size_block = [4, 8, 16, 32, 64]
_MAX_THREADS = 10
def execute(filename):
def run(size):
# for size in size_block:
cmd = ['cjpeg', '-q', '-n {}'.format(size),
'--no-save', '{}'.format(filename)]
try:
process = subprocess.Popen(cmd)
process.wait()
except Exception:
pass
runner = ThreadPool(processes=_MAX_THREADS)
result = runner.map_async(run, size_block)
result.wait()
def main():
pattener = ["*.jpg", '*.jpeg', '*.tiff', '*.bmp', "*.png"]
times = 10
_pool = ThreadPool(processes=_MAX_THREADS)
files = []
root = argv[1] if len(argv) > 1 else '.'
for pat in pattener:
files += glob.glob('{}/**/{}'.format(root, pat), recursive=True)
stdout.write('{} files found\n'.format(len(files)))
if len(files) == 0:
return
for i in range(1, times):
print('run {}/{}'.format(i, times))
result = _pool.map_async(execute, files)
result.wait()
print(result)
if __name__ == '__main__':
main()