def generate_close_and_callback(iterable, callback, environ):
 try:
  for item in iterable:
   (yield item)
 except GeneratorExit:
  if hasattr(iterable, 'close'):
   iterable.close()
  raise
 finally:
  callback(environ)

def generate_close_and_callback ( iterable , callback , environ ) : try : for item in iterable : ( yield item ) except GeneratorExit : if hasattr ( iterable , 'close' ) : iterable . close ( ) raise finally : callback ( environ )
return a generator that passes through items from iterable then calls callback .