code: def preprocess_save_to_queue(
      preprocess_fn,
      q,
      list_of_lists,
      output_files,
      segs_from_prev_stage,
      classes,
      transpose_forward,
  ):
      errors_in = []
      for i, l in enumerate(list_of_lists):
          try:
              output_file = output_files[i]
              print("preprocessing", output_file)
              d, _, dct = preprocess_fn(l)
              # print(output_file, dct)
              if segs_from_prev_stage[i] is not None:
                  assert os.path.isfile(
                      segs_from_prev_stage[i]
                  ) and segs_from_prev_stage[i].endswith(".nii.gz"), (
                      "segs_from_prev_stage"
                      " must point to a "
                      "segmentation file"
                  )
                  seg_prev = sitk.GetArrayFromImage(
                      sitk.ReadImage(segs_from_prev_stage[i])
                  )
                  # check to see if shapes match
                  img = sitk.GetArrayFromImage(sitk.ReadImage(l[0]))
                  assert all(
                      [
                          i == j
                          for i, j in zip(seg_prev.shape, img.shape)
                      ]
                  ), (
                      "image and segmentation from previous "
                      "stage don't have the same pixel array "
                      "shape! image: %s, seg_prev: %s"
                      % (l[0], segs_from_prev_stage[i])
                  )
                  seg_prev = seg_prev.transpose(transpose_forward)
                  seg_reshaped = resize_segmentation(
                      seg_prev, d.shape[1:], order=1
                  )
                  seg_reshaped = to_one_hot(seg_reshaped, classes)
                  d = np.vstack((d, seg_reshaped)).astype(np.float32)
              """There is a problem with python process communication that prevents us from communicating objects 
              larger than 2 GB between processes (basically when the length of the pickle string that will be sent is 
              communicated by the multiprocessing.Pipe object then the placeholder (I think) does not allow for long 
              enough strings (lol). This could be fixed by changing i to l (for long) but that would require manually 
              patching system python code. We circumvent that problem here by saving softmax_pred to a npy file that will 
              then be read (and finally deleted) by the Process. save_segmentation_nifti_from_softmax can take either 
              filename or np.ndarray and will handle this automatically"""
              print(d.shape)
              if np.prod(d.shape) > (
                  2e9 / 4 * 0.85
              ):  # *0.85 just to be save, 4 because float32 is 4 bytes
                  print(
                      "This output is too large for python process-process communication. "
                      "Saving output temporarily to disk"
                  )
                  np.save(output_file[:-7] + ".npy", d)
                  d = output_file[:-7] + ".npy"
              q.put((output_file, (d, dct)))
          except KeyboardInterrupt:
              raise KeyboardInterrupt
          except Exception as e:
              print("error in", l)
              print(e)
      q.put("end")
      if len(errors_in) > 0:
          print(
              "There were some errors in the following cases:",
              errors_in,
          )
          print("These cases were ignored.")
      else:
          print(
              "This worker has ended successfully, no errors to report"
          )
  
file_path: PaddleSeg/contrib/MedicalSeg/nnunet/utils/predict_utils.py
imports: import os
  import sys
  import ast
  import shutil
  import json
  import pickle
  import numpy
  from copy import deepcopy
  from typing import Tuple, Union
  import SimpleITK
  from multiprocessing import Process, Queue, Pool
  from nnunet.utils import load_remove_save
  from nnunet.transforms import resize_segmentation
  from .utils import save_segmentation_nifti_from_softmax
  from tools.preprocess_utils import get_do_separate_z, get_lowres_axis, resample_data_or_seg
label_desc: Use image node_id 3 for calling a global function with example usage: preprocess_save_to_queue(preprocess_fn, q, list_of_lists, output_files, segs_from_prev_stage, classes, transpose_forward) without return types