Anki Forums

Correctly running an operation after import

What’s the correct way of executing an operation after import? The following works, but I don’t trust it because the import is executed on a separate thread:

def someFct():
    <remove cards from mw.col>
AnkiPackageImporter.run = wrap(AnkiPackageImporter.run, someFct, "after")

In the past, some of these patches I did caused trouble, so I’d be super happy if another developer could comment on this. Thanks in advance!

The best approach would be to add a hook in the place you need, but as the importing code is due for a refactor soon, that will need to wait for a while. If you’ve tested your wrapping works and you’re not doing anything with the GUI, it will probably be fine for now.