PolarizedLightFieldMicroscopy / napari-LF

Light field imaging plugin for napari
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

Stop button should kill calibration and deconvolution processes #37

Open gschlafly opened 1 year ago

gschlafly commented 1 year ago

Description

Currently, when the Stop button is pushed, the calibration and deconvolution computation processes continue to run on the CPU/GPU. This is evident by the output in the terminal window.

Files

https://github.com/PolarizedLightFieldMicroscopy/napari-LF/blob/76f7d2a72c7f55a657f0f6d6fb02ac258bd3d5fd/src/napari_lf/_widgetLF.py#L169-L172

Solution ideas

Try to fix once https://github.com/PolarizedLightFieldMicroscopy/LFAnalyze-fundamentals/issues/7 is fixed. The line self.thread_worker.quit() should stop the computations.

amitabhverma commented 1 year ago

Adding a quote for reference : https://napari.org/stable/api/napari.qt.threading.FunctionWorker.html

!!! important

If the user does not put any yields in their function, and the function is super long, it will just hang… For instance, there’s no graceful way to kill this thread in python:

This is why it’s always advisable to use a generator that periodically yields for long-running computations in another thread.

See this stack-overflow post for a good discussion on the difficulty of killing a rogue python thread:

amitabhverma commented 1 year ago

Another useful reference : https://forum.image.sc/t/how-to-terminate-a-worker-in-thread-worker-in-napari/53822/2

Talley Lambert: yep! That’s correct. You don’t even need to actually “yield” something either. just need to sprinkle them in there. This is >obviously easiest if your long-running function already iterates somehow. But, it can be tricky in certain cases.

@thread_worker
def long_runner():
    for _ range(whetever):
        ...
        yield