yusanlin / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
1 stars 0 forks source link

Progress bar does not work in ipython notebook due to '\r' issued _after_ output string #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

The following simple example will not work in ipython notebook:

  from progressbar import ProgressBar
  import time
  pbar = ProgressBar()
  for i in pbar(range(0,10000)):
    time.sleep(0.001)

Instead of updating the progressbar, it will only show the result when the 
progress has reached 100%.

What is the expected output? What do you see instead?

Instead, the progressbar should be updated every time in the loop. This can be 
trivially achieved by changing the line 238 in progressbar/__init__.py from

  self.fd.write(self._format_line() + 'r' )

to 

  self.fd.write('\r' + self._format_line() )

What version of the product are you using? On what operating system?
ipython 0.13 (+Chrome)
progressbar 2.2

Original issue reported on code.google.com by I3RunCo...@googlemail.com on 27 Nov 2012 at 9:49

GoogleCodeExporter commented 9 years ago
Some experimentation and googling suggests that the problem is not the timing 
of '\r' issuance, but that '\r' in ipython notebook doesn't do what it does in 
the terminal, since "IPython Notebook is not a terminal emulator". Therefore, 
in a terminal IPython instance:
In [1]: print 'hello\rgoodbye'
goodbye

whereas in IPython Notebook, you get:
In [2]: print 'hello\rgoodbye'

hello
goodbye

Issue 27 on this tracker suggests the use of a javascript implementation.

Original comment by pco...@gmail.com on 4 Dec 2012 at 7:55

GoogleCodeExporter commented 9 years ago
Hi Peter, 
in IPython 0.13.1 (+Chrome), I get identical behavior in the notebook and the 
shell:

In Notebook
In [1]: print 'Hello\rGoodbye'
Goodbye

In IPython shell:
In [1]: print 'Hello\rGoodbye'
Goodbye

Anyhow - thanks for pointing me to the fancy javascript implementation.

Original comment by I3RunCo...@googlemail.com on 4 Dec 2012 at 8:15

GoogleCodeExporter commented 9 years ago
I'm merging this into issue 27.

Original comment by nilton.v...@gmail.com on 25 Dec 2012 at 7:14

GoogleCodeExporter commented 9 years ago
Minor comment, but in the suggested work-around (which works for me) the line 
is actually 283, not 238. This is verified to work for progressbar 2.3 using 
Python 2.7.3 and IPython 0.13.1 on Windows

Original comment by josh.hem...@gmail.com on 28 May 2013 at 9:22