Thanks for all your answers. I have decided that my own design is 'good enough' for my own use on my own machine. In fact, I like the way the image develops, serving as its own 'progress bar'.
Fork and thread solutions are beyond my current skill. That has got to change. (future versions???). The 'class' suggestion seems like a minor change which provides the 'stop' function in a natural way. I expect to adopt it soon. I do not see much difference between the global $y and the closure over $y. The class approach makes that issue moot anyhow.