behavior with block=False?

The code below works exactly as I expect with block=True. It does not work with block=False.
In that case, the plot window is opened, but it just contains garbage from other displayed windows (eg. a pixmap buffer that was never cleared) and the plot is never actually drawn. I assume this is unintended behavior. Does it work properly on other systems? My goal is to draw a plot, and then later update (eg. overwrite) the plot with new data, without requiring user interaction.
I am running Python 3.8.8 on Linux 5.4.0-124-generic #140-Ubuntu (Linux Mint 20 Cinnamon 4.6.7),
and Matplotlib version 3.3.4

import matplotlib.pyplot as plt
import numpy as np
import time

while True:
  data = np.random.rand(20)

System: Kernel: 5.4.0-124-generic x86_64 bits: 64 compiler: gcc v: 9.4.0
Desktop: Cinnamon 4.6.7 wm: muffin dm: LightDM Distro: Linux Mint 20 Ulyana
base: Ubuntu 20.04 focal
Machine: Type: Desktop Mobo: Compulab model: fitlet2 v: 1.1 serial:
UEFI: American Megatrends v: FLT2.MBM2. date: 07/05/2018
CPU: Topology: Quad Core model: Intel Celeron J3455 bits: 64 type: MCP arch: Goldmont rev: 9
L2 cache: 1024 KiB
flags: lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 11980
Speed: 2190 MHz min/max: 800/2300 MHz Core speeds (MHz): 1: 2196 2: 2196 3: 2196
4: 2196
Graphics: Device-1: Intel HD Graphics 500 driver: i915 v: kernel bus ID: 00:02.0
chip ID: 8086:5a85
Display: x11 server: X.Org 1.20.13 driver: modesetting unloaded: fbdev,vesa
resolution: 1920x1080~60Hz
OpenGL: renderer: Mesa Intel HD Graphics 500 (APL 2) v: 4.6 Mesa 21.2.6
direct render: Yes

Note, following a separate comment here, I also tried adding plt.ion() before the loop. This has exactly the same result as using in that I get a garbage-filled window appear, which is then frozen and my program locks up, the window cannot even be closed with the (X) button at upper right, and I have to stop the Python program. Perhaps this is pointing to a window manager problem(?)

EDIT: I see all three versions of my test code work the same way on Python 3.10.7 running on Windows 10, the only exception being with (block=False) or plt.ion() the window opened is smaller and cleared to all white, before the program gets stuck. So apparently I have some misunderstanding about how this is supposed to work, if in fact it can work at all.

EDIT 2: I guess it is the same as this issue:

I see this has something to do with running threads. actually works as expected, meaning it displays the plot and then returns immediately without waiting for user interaction, if I type it line-by-line into an interactive session.
However, it does not do this inside a while() loop, even if the while loop is typed into an interactive session. In that case, nothing gets updated on the screen, until the while loop exits, at which point all updates are displayed at once.

It looks like the thing I wanted to do, which is display a continually refreshing plot without user interaction, cannot be simply done in this way.

Problem solved. The top answer to this question provides code that works as I had hoped.

Finally, here is the code that actually does what I originally wanted.

import matplotlib.pyplot as plt
import numpy as np
import time


fig = plt.figure()
ax = fig.add_subplot(111)

while True:
    data = np.random.rand(20)
    line1, = ax.plot(data)
    plt.cla()     # clear previous data