From e9f98f44c435e198dbfdb1cc713883c48fed1f7b Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Sun, 29 Aug 2021 20:19:52 -0400 Subject: [PATCH] Handle multiprocessing exceptions in extract_assets.py (#925) * Handle multiprocessing exceptions in extract_assets.py * Update extract_assets.py Co-authored-by: Dragorn421 * Add TypeError Co-authored-by: Dragorn421 --- extract_assets.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/extract_assets.py b/extract_assets.py index 68c8daf113..7f02be04ca 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import argparse -from multiprocessing import Pool, cpu_count, Event, Manager +from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError import os import json import time @@ -103,10 +103,18 @@ def main(): if file.endswith(".xml"): xmlFiles.append(fullPath) - numCores = cpu_count() - print("Extracting assets with " + str(numCores) + " CPU cores.") - with Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, args.unaccounted, extractedAssetsTracker, manager)) as p: - p.map(ExtractFunc, xmlFiles) + try: + numCores = cpu_count() + print("Extracting assets with " + str(numCores) + " CPU cores.") + with Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, args.unaccounted, extractedAssetsTracker, manager)) as p: + p.map(ExtractFunc, xmlFiles) + except (ProcessError, TypeError): + print("Warning: Multiprocessing exception ocurred.", file=os.sys.stderr) + print("Disabling mutliprocessing.", file=os.sys.stderr) + + initializeWorker(mainAbort, args.unaccounted, extractedAssetsTracker, manager) + for singlePath in xmlFiles: + ExtractFunc(singlePath) with open(EXTRACTED_ASSETS_NAMEFILE, 'w', encoding='utf-8') as f: serializableDict = dict()