How can I accessam trying to implement multiprocessing, but I am having difficulties accessing information from the 'data_inputs' object withinscans that I'm passing through the process_scanpool.map() method without declaring it as a global variable?function
What I want my code to look likeBefore multiprocessing (this works perfectly):
deffor process_scan(sc) in scans:
#how tomy_file access= data_inputs?scans[sc].resources['DICOM'].files[0]
After multiprocessing (does not work, error shown below):
def process(the_scan):
my_file = data_inputs[sc]the_scan.resources['DICOM'].files[0]
def another_method():
...
pool = Pool(os.cpu_count())
pool.map(process_scanprocess, data_inputs[scans[sc] for sc in scans])
another_method()
What it currently looks llikeMore information about the scan object:
forprint(type(scans))
#<class sc'xnat.core.XNATListing'>
print in(scans)
#<XNATListing data_inputs{(ID_7a037c2d39, unknown):
<CtScanData unknown (ID_7a037c2d39)>}>
print my_file(sc)
#ID_7a037c2d39
print(scans[sc])
#CtScanData =unknown data_inputs[sc].resources['DICOM'](ID_7a037c2d39)> /data/projects/test/subjects/XNAT_S00004/experiments/XNAT_E00004/scans/ID_7a037c2d39/resources/5/files/ID_0a0eebac2.files[0]dcm
WhyThe error I need data_inputs[sc]:
print(sc)
ID_7a037c2d39
print(data_inputs[sc])
CtScanData unknown (ID_7a037c2d39)> /data/projects/test/subjects/XNAT_S00004/experiments/XNAT_E00004/scans/ID_7a037c2d39/resources/5/files/ID_0a0eebac2.dcm
print(type(data_inputs))
<class 'xnat.core.XNATListing'>
print(data_inputs)
<XNATListing {(ID_7a037c2d39, unknown): <CtScanData unknown (ID_7a037c2d39)>}>
Error from the revisionam getting with 'After multiprocessing' code:
---> 24 pool.map(process_scanprocess, [data_inputs[sc][scans[sc] for sc in data_inputs]scans])
~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in map(self, func, iterable, chunksize)
266 in a list that is returned.
267 '''
--> 268 return self._map_async(func, iterable, mapstar, chunksize).get()
269
270 def starmap(self, func, iterable, chunksize=None):
~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):
~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in _handle_tasks(taskqueue, put, outqueue, pool, cache)
429 break
430 try:
--> 431 put(task)
432 except Exception as e:
433 job, idx = task[:2]
~/opt/anaconda3/lib/python3.7/multiprocessing/connection.py in send(self, obj)
204 self._check_closed()
205 self._check_writable()
--> 206 self._send_bytes(_ForkingPickler.dumps(obj))
207
208 def recv_bytes(self, maxlength=None):
~/opt/anaconda3/lib/python3.7/multiprocessing/reduction.py in dumps(cls, obj, protocol)
49 def dumps(cls, obj, protocol=None):
50 buf = io.BytesIO()
---> 51 cls(buf, protocol).dump(obj)
52 return buf.getbuffer()
53
TypeError: can't pickle module objects