Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import multiprocessing
- import xml.etree.ElementTree as ET
- import time
- import sys
- import re
- def work_processor(host_item, output_queue):
- # print("Processing ->" + host_item.attrib['name'])
- block_summary = {}
- block_issues = []
- try:
- # !!! big work here with host_item!!!
- result = {
- "summary": block_summary,
- "issues": block_issues
- }
- return result
- except Exception as e:
- result = {
- "summary": block_summary,
- "issues": block_issues,
- "error" : str(e)
- }
- output_queue.put(result)
- def start_point(xml_report_file):
- try:
- dom = ET.parse(open(xml_report_file, "r"))
- root = dom.getroot()
- except Exception as e:
- print("Exception - {}".format(str(e)))
- return None
- host_report_items = [host_report for root_items in root if root_items.tag == 'Report' for host_report in root_items]
- print("Data loaded...")
- start_time = time.time()
- result_data = multiprocessing.Queue(0)
- process_list = [multiprocessing.Process(target=work_processor, args=(item, result_data,)) for item in host_report_items]
- for p in process_list:
- p.start()
- print("Processes launched... ")
- for p in process_list:
- p.join()
- print("Processes finished... ")
- results = [result_data.get() for _p in process_list]
- print("Time consumed:{}".format(time.time() - start_time))
- print(len(results))
- if __name__== '__main__':
- file_name = "data.xml"
- start_point(file_name)
Advertisement
Add Comment
Please, Sign In to add comment