Ignore TaskManager's on_done callback if collection unloaded (#4076)

* Ignore TaskManager's on_done callback if collection unloaded

* Check col.db
This commit is contained in:
Abdo 2025-06-13 06:45:41 +03:00 committed by GitHub
parent 6004616672
commit ccc42227d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,8 +84,15 @@ class TaskManager(QObject):
fut = executor.submit(task, **args)
if on_done is not None:
def wrapped_done(future: Future) -> None:
if uses_collection and not (self.mw.col and self.mw.col.db):
print(f"Ignored on_done as collection unloaded: {repr(on_done)}")
return
on_done(future)
fut.add_done_callback(
lambda future: self.run_on_main(lambda: on_done(future))
lambda future: self.run_on_main(lambda: wrapped_done(future))
)
return fut