Clearing the buffer of a display pack 2.8

I wrote a micro Python script that uses a raspberry pi pico to drive the display pack 2.8. I cannot seem to clear the display buffer when repeating a graphics script that I wrote . After trying many things I noticed the same problem exists for the demo scripts in the repository:
github.com/ pimoroni-pico/micropython/examples/gfx_pack. In particular the rainbow_wheel.py. How can I clear the buffer properly and completely without momentarily displaying prior graphics from the previous session?

My script plots a line at various angles starting at 0° ending at 180°. After each line is drawn, I clear the display with the clear display () function listed below.
When I run the script to completion it sequences through all of the plots of lines and stops. When I restart the program there is no residual display of a line from the previous execution of the script. However, when I terminate the program in Thonny, before all the lines are drawn, by issuing the Stop command, the display is as follows when I run the script again. There is a momentary flash of the display and then an image appears momentarily of the last line I drew appears before terminating the prior session. Then the script continues to run properly. I have tried many ways to clear the display. Nothing helps.

def clear_display():
display.set_pen(0)
display. Clear()
display. Update()
/

I pulled this from one of my files that worked OK.

BLACK = display.create_pen(0, 0, 0)

def clear():
    display.set_pen(BLACK)
    display.clear()
    display.update()

Then I just run clear() to clear it.

Thanks but I already used this in my sketch and it did not work.I need to access the buffer directly.

Your code is different from mine. Did you try my code?

I tried it but it did not help. I believe it is a problem with the hardware buffer that cannot be cleared before executing the micro Python code.

Ok. My code as posted clears the buffer that is on the Pico, display.clear() then transfers that empty buffer to display pack display.update(). It looks like you are fighting something left in the actual displays buffer. I didn’t clue into that when I read your original post. Issuing that stop command is leaving things behind in the displays buffer.
Do you do clear display / display update before executing your while true loop?

Yes, I do the following before executing my while true loop.

[clear display / display update ]

Ok, you may have to do a reset or power cycle to clear that left over data in the buffer.

I tried to do a hard reset via the software command machine.reset(). Then I get the error message:
PROBLEM IN THONNY’S BACK-END: Exception while handling ‘Run’ (ConnectionError: EOF).
See Thonny’s backend.log for more info.
You may need to press “Stop/Restart” or hard-reset your MicroPython device and try again.

That will happen, you just have to connect again.