Slicer doesn't print anything during for loops even with sys.stdout.flush()

I’m developing a 3DSlicer extension that includes very long processes (huge for loops). I’d like to show the progress with a progressbar (like tqdm) or at least print some progress information at each iteration but nothing is printed in Slicer’s python console before the end of the process.
This is what I obtain with tqdm, but only at the end as previously said.
image

I would be grateful for any help!

Have you tried adding slicer.app.processEvents() after each print statement to trigger the Qt update?