code: def loadpkl(infile):
      """Load a zipped or plain cPickled file."""
      infile = Path(infile)
      fmlogger.debug("Loading pkl: %s", infile)
      pklopen = gzip.open if infile.suffix == ".pklz" else open
  
      t = time()
      timeout = float(config.get("execution", "job_finished_timeout"))
      timed_out = True
      while (time() - t) < timeout:
          if infile.exists():
              timed_out = False
              break
          fmlogger.debug(f"'{infile}' missing; waiting 2s")
          sleep(2)
      if timed_out:
          error_message = (
              "Result file {} expected, but "
              "does not exist after ({}) "
              "seconds.".format(infile, timeout)
          )
          raise OSError(error_message)
  
      with pklopen(str(infile), "rb") as pkl_file:
          pkl_contents = pkl_file.read()
  
      pkl_metadata = None
  
      # Look if pkl file contains version metadata
      idx = pkl_contents.find(b"\n")
      if idx >= 0:
          try:
              pkl_metadata = json.loads(pkl_contents[:idx])
          except (UnicodeDecodeError, json.JSONDecodeError):
              # Could not get version info
              pass
          else:
              # On success, skip JSON metadata
              pkl_contents = pkl_contents[idx + 1 :]
  
      # Pickle files may contain relative paths that must be resolved relative
      # to the working directory, so use indirectory while attempting to load
      unpkl = None
      try:
          with indirectory(infile.parent):
              unpkl = pickle.loads(pkl_contents)
      except UnicodeDecodeError:
          # Was this pickle created with Python 2.x?
          with indirectory(infile.parent):
              unpkl = pickle.loads(
                  pkl_contents, fix_imports=True, encoding="utf-8"
              )
          fmlogger.info(
              "Successfully loaded pkl in compatibility mode."
          )
      # Unpickling problems
      except Exception as e:
          if pkl_metadata and "version" in pkl_metadata:
              if pkl_metadata["version"] != version:
                  fmlogger.error(
                      """\
  Attempted to open a results file generated by Nipype version %s, \
  with an incompatible Nipype version (%s)""",
                      pkl_metadata["version"],
                      version,
                  )
                  raise e
          fmlogger.warning(
              """\
  No metadata was found in the pkl file. Make sure you are currently using \
  the same Nipype version from the generated pkl."""
          )
          raise e
  
      if unpkl is None:
          raise ValueError("Loading %s resulted in None." % infile)
  
      return unpkl
  
imports: import sys
  import pickle
  import errno
  import subprocess
  import gzip
  import hashlib
  import locale
  from hashlib import md5
  import os
  import os.path
  import re
  import shutil
  import contextlib
  import posixpath
  from pathlib import Path
  import simplejson
  from time import sleep, time
  from ..None import logging, config, __version__
  from .misc import is_container
label_desc: Use image node_id 20 for calling a global function with example usage: loadpkl(infile) and returns: unpkl