From 8e1146b8e1bea3ca067008d53b2d9ea01d19ecb6 Mon Sep 17 00:00:00 2001 From: Ramon Correa Date: Mon, 5 Apr 2021 17:00:46 -0400 Subject: [PATCH] added call to process join and close to make sure pool is terminated. modified one call of pool in line 348 to use core_count --- modules/png-extraction/ImageExtractor.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/png-extraction/ImageExtractor.py b/modules/png-extraction/ImageExtractor.py index 5e22212..8d33b1e 100644 --- a/modules/png-extraction/ImageExtractor.py +++ b/modules/png-extraction/ImageExtractor.py @@ -1,26 +1,24 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import numpy as np -import pandas as pd -import pydicom as dicom -import png, os, glob -import PIL as pil -from pprint import pprint -import hashlib +import os +import glob from shutil import copyfile -import logging -from multiprocessing import Pool +import hashlib import json import sys import subprocess +import logging +from multiprocessing import Pool import pdb +import time import pickle +import numpy as np +import pandas as pd +import pydicom as dicom #pydicom imports needed to handle data errrors from pydicom import config from pydicom import datadict from pydicom import values -from subprocess import Popen -import time with open('config.json', 'r') as f: niffler = json.load(f) @@ -243,7 +241,7 @@ def fix_mismatch_callback(raw_elem, **kwargs): pass else: raw_elem = raw_elem._replace(VR=vr) - break # I want to exit immediately after change is applied + break return raw_elem @@ -347,7 +345,7 @@ def fix_mismatch(with_VRs=['PN', 'DS', 'IS']): filedata=data total = len(chunk) stamp = time.time() - p = Pool(os.cpu_count()) + p = Pool(core_count) res = p.imap_unordered(extract_images,range(len(filedata))) for out in res: (fmap,fail_path,err) = out @@ -358,6 +356,8 @@ def fix_mismatch(with_VRs=['PN', 'DS', 'IS']): logging.error(err_msg) else: fm.write(fmap) + p.join() + p.close() fm.close() logging.info('Chunk run time: %s %s', time.time() - t_start, ' seconds!')