<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def preserve_current_canvas():
 """ Context manager which ensures that the current canvas remains the current canvas when the context is left. """

    old = ROOT.gPad
    try:
        yield
    finally:
        if old:
            old.cd()
        elif ROOT.gPad:
            # Put things back how they were before.
            with invisible_canvas():
                # This is a round-about way of resetting gPad to None.
                # No other technique I tried could do it.
                pass