Skip to content

Commit

Permalink
added call to process join and close to make sure pool is terminated.
Browse files Browse the repository at this point in the history
modified one call of pool in line 348 to use core_count
  • Loading branch information
ramon349 committed Apr 5, 2021
1 parent 9fcc433 commit 8e1146b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions modules/png-extraction/ImageExtractor.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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!')

Expand Down

0 comments on commit 8e1146b

Please sign in to comment.