code: def create_pyscript(node, updatehash=False, store_exception=True):
      # pickle node
      timestamp = strftime("%Y%m%d_%H%M%S")
      if node._hierarchy:
          suffix = f"{timestamp}_{node._hierarchy}_{node._id}"
          batch_dir = os.path.join(
              node.base_dir, node._hierarchy.split(".")[0], "batch"
          )
      else:
          suffix = f"{timestamp}_{node._id}"
          batch_dir = os.path.join(node.base_dir, "batch")
      if not os.path.exists(batch_dir):
          os.makedirs(batch_dir)
      pkl_file = os.path.join(batch_dir, "node_%s.pklz" % suffix)
      savepkl(pkl_file, dict(node=node, updatehash=updatehash))
      mpl_backend = node.config["execution"]["matplotlib_backend"]
      # create python script to load and trap exception
      cmdstr = """import os
  import sys
  
  can_import_matplotlib = True #Silently allow matplotlib to be ignored
  try:
      import matplotlib
      matplotlib.use('%s')
  except ImportError:
      can_import_matplotlib = False
      pass
  
  import os
  value = os.environ.get('NIPYPE_NO_ET', None)
  if value is None:
      # disable ET for any submitted job
      os.environ['NIPYPE_NO_ET'] = "1"
  from nipype import config, logging
  
  from nipype.utils.filemanip import loadpkl, savepkl
  from socket import gethostname
  from traceback import format_exception
  info = None
  pklfile = '%s'
  batchdir = '%s'
  from nipype.utils.filemanip import loadpkl, savepkl
  try:
      from collections import OrderedDict
      config_dict=%s
      config.update_config(config_dict)
      ## Only configure matplotlib if it was successfully imported,
      ## matplotlib is an optional component to nipype
      if can_import_matplotlib:
          config.update_matplotlib()
      logging.update_logging(config)
      traceback=None
      cwd = os.getcwd()
      info = loadpkl(pklfile)
      result = info['node'].run(updatehash=info['updatehash'])
  except Exception as e:
      etype, eval, etr = sys.exc_info()
      traceback = format_exception(etype,eval,etr)
      if info is None or not os.path.exists(info['node'].output_dir()):
          result = None
          resultsfile = os.path.join(batchdir, 'crashdump_%s.pklz')
      else:
          result = info['node'].result
          resultsfile = os.path.join(info['node'].output_dir(),
                                 'result_%%s.pklz'%%info['node'].name)
  """
      if store_exception:
          cmdstr += """
      savepkl(resultsfile, dict(result=result, hostname=gethostname(),
                                traceback=traceback))
  """
      else:
          cmdstr += """
      if info is None:
          savepkl(resultsfile, dict(result=result, hostname=gethostname(),
                                traceback=traceback))
      else:
          from nipype.pipeline.plugins.base import report_crash
          report_crash(info['node'], traceback, gethostname())
      raise Exception(e)
  """
      cmdstr = cmdstr % (
          mpl_backend,
          pkl_file,
          batch_dir,
          node.config,
          suffix,
      )
      pyscript = os.path.join(batch_dir, "pyscript_%s.py" % suffix)
      with open(pyscript, "w") as fp:
          fp.writelines(cmdstr)
      return pyscript
  
file_path: nipype/nipype/pipeline/plugins/tools.py
imports: import os
  import getpass
  from socket import gethostname
  import sys
  import uuid
  from time import strftime
  from traceback import format_exception
  from ...None import logging
  from ...utils.filemanip import savepkl, crash2txt
label_desc: Use image node_id 3 for calling a global function with example usage: create_pyscript(node, updatehash, store_exception) and returns: pyscript