rasbt / pyprind

PyPrind - Python Progress Indicator Utility
BSD 3-Clause "New" or "Revised" License
547 stars 65 forks source link

pyprind ProgBar monitor=True fails #6

Closed vmirly closed 10 years ago

vmirly commented 10 years ago

I tried to use pyprind to see the progress of reading a big file, and it works really nicely with monitor=False, but doesn't work if I use monitor=True:

my_bar = pyprind.ProgBar(line_cnt, stream=1, width=30, track_time=True, title='Reading Input File', monitor=True)
File "/usr/local/lib/python2.7/dist-packages/pyprind/progbar.py", line 27, in __init__
Prog.__init__(self, iterations, track_time, stream, title, monitor)
File "/usr/local/lib/python2.7/dist-packages/pyprind/prog_class.py", line 24, in __init__
import psutil

Here is my source:

d = np.array([])
## setup the progress bar indicator
line_cnt = subprocess.check_output(['wc', '-l', input_file])
line_cnt = int(line_cnt.split()[0])
my_bar = pyprind.ProgBar(line_cnt, stream=1, width=30, track_time=True, title='Reading Input File', monitor=False)

## read the inputfile into a numpy array
with open(input_file, 'r') as fp:
    for line in fp:
        d = np.append(d, line.strip())
        my_bar.update()
print(d.shape)
rasbt commented 10 years ago

Hey, Vahid, thanks for the comment! Have you installed the psutil package? You can quickly check by typing import psutil into your Python shell. If it is not installed, you can simply do a pip install psutil and it should work alright. Let me know if you have further troubles!

vmirly commented 10 years ago

yup, that solved the issue! thanks :) The error message wasn't pointing me to psutil!

One more thing, what is this warning:

 Warning: No valid output stream.
rasbt commented 10 years ago

Nice! Hm, but about the warning: This actually shouldn't happen. Did you try to provide it a custom output stream?

When I look at my code, this should only happen if one of those statements (see below) is False:

>>> import os
>>> import sys
>>> os.isatty(sys.stderr.fileno())
True
>>> os.isatty(sys.stderr.fileno())
True