This is (almost) the solution you want. It’s not as simple as you have imagined because you need to get an async operation working in collaboration with Streamlit’s rerun mechanics. You’ll need to modify the while loop condition to allow the watch to be stopped and started (i.e., a stopwatch).
HTH,
Arvindra