Users need a way to stop the segmentation process
If a user segments many files i.e >3000 and then realises they made a mistake, they have no way to stop the segmentation process.
One idea to solve this is a button on the segmentation progress widget that say 'cancel' that will send a message to the server to stop segmentation.
I agree, I will try to add a UI element to make this work. Any ideas on how to implement this on the backend?
It's a bit tricky. The segmentation process, found here: https://github.com/Abe404/root_painter/blob/a019d627825725ef9ebebef34aa1713673626a96/trainer/trainer.py#L412
Segments the files as fast as possible without checking for any other instructions from the client.
The 'cancel_segmentation' instruction could be implemented via a new instruction type that we send to the server. Then in the segmentation process (essentially just a loop, see linked code), we could check for any new 'cancel_segmentation' instructions. My concern with this is that on some systems the mounted file system can be a little slow, so I'm concerned that listing and reading the instructions from the instructions directory to check for 'cancel' before segmenting each image, could lead to the segmentation processing being slower overall (considering we are talking about many thousands of files here).
That said, not having a way to cancel a long-running segmentation process is a bit ridiculous. One idea is to have the instructions check be somewhat asynchronous/in another thread but that introduces some potential complexity/bugs I'd rather not think about.
Perhaps we just have to bite the bullet and check the instruction directory for a 'cancel_segmentation' instruction every time before segmenting an image. We could do this just for situations where multiple files are being segmented, for segmentations of single images having to check for a 'cancel_segmentation' instruction is overkill.