@contextmanager
def closing_if_possible(maybe_closable):
 try:
  (yield maybe_closable)
 finally:
  close_if_possible(maybe_closable)

@ contextmanager def closing_if_possible ( maybe_closable ) : try : ( yield maybe_closable ) finally : close_if_possible ( maybe_closable )
like contextlib .