Add parallel processing

This commit is contained in:
Quantum 2020-09-26 19:43:45 -04:00
parent a46bfd7916
commit f13e4260d4

View file

@ -2,6 +2,9 @@ import argparse
import os
import sys
import traceback
from multiprocessing import cpu_count
from multiprocessing.pool import ThreadPool
from threading import Lock
from win2xcur import shadow
from win2xcur.parser import open_blob
@ -30,15 +33,17 @@ def main() -> None:
help='color of the shadow')
args = parser.parse_args()
print_lock = Lock()
check_xcursorgen()
for file in args.files:
def process(file):
name = file.name
blob = file.read()
try:
cursor = open_blob(blob)
except Exception:
with print_lock:
print('Error occurred while processing %s:' % (name,), file=sys.stderr)
traceback.print_exc()
else:
@ -50,6 +55,9 @@ def main() -> None:
with open(output, 'wb') as f:
f.write(result)
with ThreadPool(cpu_count()) as pool:
pool.map(process, args.files)
if __name__ == '__main__':
main()