code: def ipython_tb_clear_frames(func):
      """Reclaim general/GPU RAM on any exception under ipython environment (decorator)
  
      ipython has a feature where it stores tb with all the locals() tied in, which
      prevents gc.collect from freeing those variables, therefore we cleanse the tb
      before handing it over to ipython.
  
      This is a decorator to be used with any function that needs this workaround:
      *) under non-ipython environment it doesn't do anything.
      *) under ipython it strips tb of `locals()`
  
      This workaround has a side-effect of not being able to use `%debug` or
      `%pdb` magic, because the debugger needs the `locals()` of each involved
      frame to be there.
      """
  
      @functools.wraps(func)
      def wrapper(*args, **kwargs):
          if not IS_IN_IPYTHON:
              return func(*args, **kwargs)
  
          try:
              return func(*args, **kwargs)
          except:
              exc_type, exc_val, exc_tb = sys.exc_info()
              traceback.clear_frames(exc_tb)
              raise exc_type(exc_val).with_traceback(exc_tb) from None
  
      return wrapper
  
file_path: ipyexperiments/ipyexperiments/utils/ipython.py
imports: import functools
  import os
  import sys
  import traceback
label_desc: Use image node_id 2 for calling a global function with example usage: ipython_tb_clear_frames(func) and returns: wrapper, func, func