Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread worker and progress bar for model loading (and other long running computation) #202

Closed
constantinpape opened this issue Sep 22, 2023 · 4 comments
Assignees
Milestone

Comments

@constantinpape
Copy link
Contributor

We should wrap long running computation into a thread worker, so that it does not block the viewer, and that a progress bar / "I am working sign" is shown.

See pyapp-kit/magicgui#579 for how to do that with magicgui.

For now, we could try it where the model is loaded in the 2d annotation tool, https://github.com/computational-cell-analytics/micro-sam/blob/master/micro_sam/sam_annotator/annotator_2d.py#L225 and will eventually refcator it.

@GenevieveBuckley
Copy link
Collaborator

Here's the example code I left in a comment on a different thread:

from time import sleep
from magicgui import magic_factory
from magicgui.tqdm import tqdm


@magic_factory(
    threshold={"widget_type": "FloatSlider", "max": 20},
    call_button="Calculate!",
)
def example_magic_widget(
    img_layer: "napari.layers.Image",
    threshold: "float"
) -> "napari.types.LabelsData":
    with tqdm() as pbar:
        @thread_worker(connect={"finished": lambda: pbar.progressbar.hide()})
        def long_running():
            sleep(5)

        long_running()

@constantinpape
Copy link
Contributor Author

@GenevieveBuckley: You wrote in the other thread

Ok, I had a strangely difficult time combining a thread worker with an indeterminate progress bar in the napari plugin widget. Here's what it should look like: ...

Just to clarify: the solution you posted here is now working, correct?

@constantinpape
Copy link
Contributor Author

This is implemented now in #235

@constantinpape
Copy link
Contributor Author

See #263 for follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants