diff --git a/mat2 b/mat2 index a3697d9f821326d1d7e12eb6aac7c7fe1e339c33..71b5b8ee4d9f5365d3efe46a5f7b70330e36c5a5 100755 --- a/mat2 +++ b/mat2 @@ -7,7 +7,7 @@ import mimetypes import argparse import logging import unicodedata -import multiprocessing +from multiprocessing import Pool, cpu_count try: from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS @@ -53,9 +53,6 @@ def create_arg_parser() -> argparse.ArgumentParser: help='how to handle unknown members of archive-style ' 'files (policy should be one of: %s) [Default: abort]' % ', '.join(p.value for p in UnknownMemberPolicy)) - parser.add_argument('-p', '--parallel', metavar='parallel', default='4', - help='how many processes can be spawned [Default: 4]') - info = parser.add_mutually_exclusive_group() info.add_argument('-s', '--show', action='store_true', @@ -153,11 +150,7 @@ def __get_files_recursively(files: List[str]) -> Generator[str, None, None]: def main() -> int: arg_parser = create_arg_parser() args = arg_parser.parse_args() - - if args.parallel.isdigit(): - async_pool = multiprocessing.Pool(processes=int(args.parallel)) - else: - arg_parser.print_help() + async_pool = Pool(processes=cpu_count()) if args.verbose: logging.basicConfig(level=logging.INFO) @@ -178,8 +171,7 @@ def main() -> int: if args.show: for f in __get_files_recursively(args.files): procs.append(async_pool.apply_async(show_meta, (f,))) - results = [p.get() for p in procs] - return 0 if all(r for r in results) else -1 + return 0 if all(r for r in [p.get() for p in procs]) else -1 else: policy = UnknownMemberPolicy(args.unknown_members) @@ -188,8 +180,7 @@ def main() -> int: for f in __get_files_recursively(args.files): procs.append(async_pool.apply_async(clean_meta, (f, args.lightweight, policy))) - results = [p.get() for p in procs] - return 0 if all(r for r in results) else -1 + return 0 if all(r for r in [p.get() for p in procs]) else -1 if __name__ == '__main__':