I have a custom management command which calls a method in another class,
which fetches lots of data from a third-party API. Fetching the data could
take a few seconds or it could take over an hour, depending on the quantity.

I'd like to display progress on the command line, so the user knows the
command's still going but am struggling with a good way to do this.
Criteria:

a) A single line that updates as the task progresses.
b) That line doesn't display while running unit tests (or is very easy to
disable for tests).
c) That line doesn't display while running the command automatically (via
cron or whatever).

Things I've tried so far:

*1) Using print()*, e.g.:

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

In a loop, this nicely shows a single line that constantly updates with
progress. But print() is nasty and when I run my unit tests, this output is
displayed among the testing output. I assume it'll also be a pain to have
that output when running the commands scheduled with cron (or whatever).

*2) Using Django logging.* This is "better" than print(), and doesn't mess
up test output, but as far as I can tell there's no way to display a
single, constantly updated, line showing progress. It's only going to show
one line after another:

    Fetched 1 of 3000
    Fetched 2 of 3000
    Fetched 3 of 3000

*3) Using tqdm* <https://pypi.python.org/pypi/tqdm>. Makes it easy to
display a command line progress bar but, again, I end up with loads of
progress bars displaying in my test output, and I assume it'll do the same
when scheduling the task to run.


Have I missed a standard way to do this? Or is there a way I haven't found
to easily suppress tqdm's output during tests and when running the task
scheduled? I can't be the first to have wanted this...

Thanks,
Phil

-- 
http://www.gyford.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAU%3D2qRS8_HBadL5Oqga8h8k7yRnuu2NHyH%2B60PT_-Pi7RyskQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to