code: def cleanup():
      """
      Delete keys in old format from the compiledir.
  
      Old clean up include key in old format or with old version of the c_code:
      1) keys that have an ndarray in them.
         Now we use a hash in the keys of the constant data.
      2) key that don't have the numpy ABI version in them
      3) They do not have a compile version string
  
      If there is no key left for a compiled module, we delete the module.
  
      """
      compiledir = theano.config.compiledir
      for directory in os.listdir(compiledir):
          file = None
          try:
              try:
                  filename = os.path.join(
                      compiledir, directory, "key.pkl"
                  )
                  file = open(filename, "rb")
                  # print file
                  try:
                      keydata = pickle.load(file)
                      for key in list(keydata.keys):
                          have_npy_abi_version = False
                          have_c_compiler = False
                          for obj in flatten(key):
                              if isinstance(obj, np.ndarray):
                                  # Reuse have_npy_abi_version to
                                  # force the removing of key
                                  have_npy_abi_version = False
                                  break
                              elif isinstance(obj, string_types):
                                  if obj.startswith(
                                      "NPY_ABI_VERSION=0x"
                                  ):
                                      have_npy_abi_version = True
                                  elif obj.startswith(
                                      "c_compiler_str="
                                  ):
                                      have_c_compiler = True
                              elif isinstance(
                                  obj, (theano.gof.Op, theano.gof.Type)
                              ) and hasattr(
                                  obj, "c_code_cache_version"
                              ):
                                  v = obj.c_code_cache_version()
                                  if (
                                      v not in [(), None]
                                      and v not in key[0]
                                  ):
                                      # Reuse have_npy_abi_version to
                                      # force the removing of key
                                      have_npy_abi_version = False
                                      break
  
                          if (
                              not have_npy_abi_version
                              or not have_c_compiler
                          ):
                              try:
                                  # This can happen when we move the compiledir.
                                  if keydata.key_pkl != filename:
                                      keydata.key_pkl = filename
                                  keydata.remove_key(key)
                              except IOError:
                                  _logger.error(
                                      "Could not remove file '%s'. To complete "
                                      "the clean-up, please remove manually "
                                      "the directory containing it.",
                                      filename,
                                  )
                      if len(keydata.keys) == 0:
                          shutil.rmtree(
                              os.path.join(compiledir, directory)
                          )
  
                  except (EOFError, AttributeError):
                      _logger.error(
                          "Could not read key file '%s'. To complete "
                          "the clean-up, please remove manually "
                          "the directory containing it.",
                          filename,
                      )
              except IOError:
                  _logger.error(
                      "Could not clean up this directory: '%s'. To complete "
                      "the clean-up, please remove it manually.",
                      directory,
                  )
          finally:
              if file is not None:
                  file.close()
  
file_path: Theano/theano/gof/compiledir.py
imports: from __future__ import absolute_import, print_function, division
  import six.moves.cPickle
  import logging
  import os
  import shutil
  import numpy
  import theano
  from six import string_types, iteritems
  from theano import config
  from theano.gof.utils import flatten
label_desc: Use image node_id 1 for calling a global function with example usage: cleanup() without return types