I’ve been banging my head on this problem where I’m running two CollectionOps back-to-back during sync and only the first one shows progress updates. I’m using the collection_op.with_backend_progress(on_progress_func) for showing progress updates. Is this some problem where the progress dialog for the first op doesn’t close because the next op begins so soon but the next op no longer has access to the dialog?
First op runs in sync_will_start and the second in sync_did_finish:
I’ve verified that the problem seems to be that the on_progress func I pass to with_backend_progress never gets called during the second op no matter how long the op takes, which would explain why no updates are shown despite the progress_update_def having stuff to show. But why doesn’t the function get called anymore and how do I fix it?
I made a simple test addon that produces some progress updates. I found that running the test op through the menu shows the progress updates while running the same op in either sync hook shows no progress updates.
I’m not fluent enough on this topic, although I imagine it’s because you can’t have the same run_op operation in parallel, and the sync_will_start and sync_did_finish sync events finish before your first operation.
I feel like something like this could work, since second_op always waits for first_op to finish, regardless of whether sync_did_finish happens first, without blocking the main thread.
Thanks but that this seemed to only cause the second op to hang on the first_op_done.wait() call.
I think the problem may be with the sync hooks themselves doing something different compared to running an op through a menu. I tested just running a single op, either in sync_will_start in or sync_did_finish, and the custom progress updates don’t get shown in either case.
Changing to use mw.taskman did fix this. However, this isn’t how CollectionOp is supposed to be used. I suspect there is a bug in the sync_did_finish hook. I’ll do some testing and see, if the test addon using with_backend_progress(on_progress) worked in a previous Anki version.
Test addon with working custom progress updates using mw.taskman instead
import time
from typing import Optional, Callable
from aqt.gui_hooks import sync_will_start, sync_did_finish
from aqt.operations import CollectionOp
from anki.collection import OpChanges
from aqt import mw
from aqt.qt import QAction