Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing task progress from a Django management command

I have some Django management commands that call methods in other classes to fetch data from APIs. These tasks can take a long time to complete, and I'd like to show progress in the console in a concise manner.

I could use print() to output a single line like "Fetched 22 of 3000" that writes over itself, using something like:

print('Fetched %d of %d' % (n, total) + ' '*30, end='\r')

But using print() seems a bit nasty, and it gets output to the console when tests are run. So it seems better to use logging, but I can't see a way using that to display a single, constantly updated, "progress" line in the console.

Is there a nice way to do this?

like image 625
Phil Gyford Avatar asked May 07 '16 16:05

Phil Gyford


1 Answers

Maybe tqdm is a helpful python package for you.

like image 144
sascha Avatar answered Oct 11 '22 13:10

sascha