def _reduce_function(func, globs):
 if func.__closure__:
  cells = [cell.cell_contents for cell in func.__closure__]
 else:
  cells = None
 return (_reduce_code(func.__code__), globs, func.__name__, cells)

def _reduce_function ( func , globs ) : if func . __closure__ : cells = [ cell . cell_contents for cell in func . __closure__ ] else : cells = None return ( _reduce_code ( func . __code__ ) , globs , func . __name__ , cells )
reduce a python function and its globals to picklable components .