@contextmanager<EOL>def delayed_close(closable):
close = getattr(closable, "<STR_LIT>", None)<EOL>if close:<EOL><INDENT>def replacement_close(*args, **kw):<EOL><INDENT>"""<STR_LIT>"""<EOL>pass<EOL><DEDENT>setattr(closable, "<STR_LIT>", replacement_close)<EOL><DEDENT>try:<EOL><INDENT>yield closable<EOL><DEDENT>finally:<EOL><INDENT>if close:<EOL><INDENT>setattr(closable, "<STR_LIT>", close)<EOL>closable.close()<EOL><DEDENT><DEDENT>
Delay close until this contextmanager dies