Python-yad Progress Bar not working in python 3.4 but works in python 2.7

576 views Asked by At

I have created a python interface for the yad program. What the code basically does is that, it generates a string which gets passed to the yad program using pythons subprocess and/or pexpect module and executes it

Now, Im facing a weird bug where I am trying to display a simple [multi]progress bar and update the bar with a certain value like this:

import yad, time

yad = yad.YAD()

x = yad.Progress(autoclose=True) # yad.MultiProgress(autoclose=True)

for i in range(0,105,5):
  print(i)
  x(i,msg=str(i)+"% done")
  time.sleep(0.5)

The problem is that, in python 2.7, it works fine(updates the bar, and closes after wards), But when it comes to python 3.4, it does not work(shows the bar, but does not update, even though the for loop prints the numbers).

Im trying to figure out what the problem is with my interface. The functions are written in such a way that, it should update the bar, but for some reason its not working in python 3.4.

Kindly help me with this problem. I am not able to figure out where the bug is.

Edit : x is a function that is returned as output when we call the yad.Progress(). Using the x, we can write some standard input to the yad. The shell equivalent of the code would be something like this:

yad --progress --auto-close
> 5
> # 5% done 
...
2

There are 2 answers

0
Thomas K On BEST ANSWER

Reposting as an answer:

Inside the wrapper module, call p.stdin.flush() after writing to the subprocess' stdin.

In Python 2, the default is to create Popen pipes without any buffering (the bufsize argument to subprocess.Popen defaults to 0). That means that any data you write is sent to the subprocess immediately. In Python 3, buffering is the default (bufsize defaults to -1, which means the default buffer size). So, for performance reasons, data is stored in memory until either the buffer fills up or you call flush.

0
kpie On

You can use print("{}/100".format(k), "\r", end="") to unprint the last % and then print the updated progress.