Great library! I'm not sure whether this is something you've already looked into/tried or if this would be a new feature addition.
Anyhow, I have a script I am running using p_tqdm and I'd like to achieve something similar to tqdm.write where you can have the progress bar fixed to the bottom whilst printed messages to stdout end up above that. The script is rather large and rather than manually going in and changing those print statements I've borrowed a SO answer to overload print.
A simple repro script is as follows:
import time
import inspect
from p_tqdm import p_map
from p_tqdm.p_tqdm import tqdm # NOTE: here I've also tried importing tqdm as `from tqdm.auto import tqdm`.. no luck
def divert_stdout_to_tqdm() -> None:
old_print = print
def new_print(*args, **kwargs) -> None:
# if tqdm.tqdm.write raises error, use builtin print
try:
tqdm.write(*args, **kwargs)
except:
old_print(*args, ** kwargs)
inspect.builtins.print = new_print
def do_stuff(num: int) -> None:
print("HIIIIII")
time.sleep(0.5)
divert_stdout_to_tqdm()
# doesn't work
results = p_map(do_stuff, range(100))
# works
for i in tqdm(range(100)):
do_stuff(i)
results = p_map(do_stuff, range(100))
doesn't work exactly as I'd intend as it produces output as such:
Great library! I'm not sure whether this is something you've already looked into/tried or if this would be a new feature addition.
Anyhow, I have a script I am running using
p_tqdm
and I'd like to achieve something similar totqdm.write
where you can have the progress bar fixed to the bottom whilst printed messages to stdout end up above that. The script is rather large and rather than manually going in and changing thoseprint
statements I've borrowed a SO answer to overloadprint
.A simple repro script is as follows:
doesn't work exactly as I'd intend as it produces output as such:
works as intended and produces output as such:
I am also not an expert in the
multiprocessing
library and it is very well possible that this is more related tomultiprocessing
than it isp_tqdm
.