casperdcl · GitHub

Writing to tqdm without conflicting tqdm bars requires use of tqdm.write() that is good enough if writing is done by our code. If external party is writing to stream that will cause tqdm to be a glitch.

import traceback
from tqdm import tqdm, trange
from time import sleep
bar = trange(10)
for i in bar:
    # Print using tqdm class method .write()
    sleep(0.1)
    try:
    	raise ValueError()
    except:
    	traceback.print_exc()
import traceback
from tqdm import tqdm, trange
from time import sleep
bar = trange(10)
for i in bar:
    # Print using tqdm class method .write()
    sleep(0.1)
    try:
    	raise ValueError()
    except:
        with tqdm.external_write_mode():
            traceback.print_exc()

Read the original on github.com ↗