Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make tqdm play nice with jenkins?

Tags:

jenkins

tqdm

Love tqdm progress bar, but when I use it on jenkins, I keep getting a bunch of weird artifacts and too much bloat in stdout (specifically, omnipresence of [A). Is there a secret mode in tqdm to make it work nicely with jenkins? Bonus points for seamless detection of non-interactive shells like jenkins. Here is what my typical output looks like:

label: 0it [00:00, ?it/s][A
[A
 16%|#6        | 5378/33302 [36:28<2:30:49,  3.09it/s]
[A
 16%|#6        | 5379/33302 [36:29<2:36:46,  2.97it/s]
[A
...
like image 699
Oleksiy Avatar asked Sep 15 '17 15:09

Oleksiy


People also ask

Can I use tqdm with multiprocessing?

Combine TQDM with multiprocessing It's a swiss knife that's used in multiple areas: analyzing and visualizing data, training machine learning models, building APIs, scraping websites, DevOps, MLOps, and obviously, much more things.

How do I run tqdm?

Using tqdm is very simple, you just need to add your code between tqdm() after importing the library in your code. You need to make sure that the code you put in between the tqdm() function must be iterable or it would not work at all.

What is tqdm range?

Ranges from 0 (average speed) to 1 (current/instantaneous speed) [default: 0.3].

Why do we use tqdm?

tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. tqdm got its name from the Arabic name taqaddum which means 'progress'.


1 Answers

I'd go with something like:

from tqdm import tqdm
import os

# try this
for i in tqdm(..., disable=None):
    ...

# alternative if the above doesn't work
for i in tqdm(..., disable=os.environ.get("JENKINS_HOME")):
    ...

# or even...
for i in tqdm(..., disable=os.environ.get("JENKINS_HOME") is not None):
    ...

Note that disable=None should automatically check things such as sys.stdout.isatty().

Unfortunately there's nothing that can be done about Jenkins not supporting CR (\r), a basic requirement of tqdm.

From https://tqdm.github.io/:

tqdm does not require any dependencies (not even curses!), just Python and an environment supporting carriage return \r and line feed \n control characters.

like image 186
casper.dcl Avatar answered Sep 19 '22 13:09

casper.dcl