Destruction of generator objects

Stefan Bellon sbellon at sbellon.de
Thu Aug 9 08:25:17 CEST 2007


On Thu, 09 Aug, Graham Dumpleton wrote:

>     result = application(environ, start_response)
>     try:
>         for data in result:
>             if data:    # don't send headers until body appears
>                 write(data)
>         if not headers_sent:
>             write('')   # send headers now if body was empty
>     finally:
>         if hasattr(result,'close'):
>             result.close()

Hm, not what I hoped for ...

Isn't it possible to add some __del__ method to the generator object
via some decorator or somehow else in a way that works even with Python
2.4 and can then be nicely written without cluttering up the logic
between consumer and producer?

-- 
Stefan Bellon



More information about the Python-list mailing list