0

I have been runing code which take over 8-10 hors for compiling. Is there any way to print the progression of the compilation in a way like 1% 2% ........99%, as we see in different applications? I could have put such progression in one of the running loops, but in that might not look convenient.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Subhadip Saha
  • 33
  • 1
  • 6
  • what have you tried so far? [tqdm](https://github.com/tqdm/tqdm) is a popular progress meter for loops, but may not work for your case – ti7 Jul 31 '21 at 05:13
  • something like, k=0 ; while(k – Subhadip Saha Jul 31 '21 at 06:07
  • 'N_S = 100 k = 0 while(k < N_S): k = k + 1 percentage = (k/N_S)*100 print(np.round(percentage, 3)," % ")' – Subhadip Saha Jul 31 '21 at 06:20
  • What 'compiling' are you talking about? Do you mean 'completion'? – hpaulj Jul 31 '21 at 07:03
  • @hpaulj lets see my last comment, so I want to monitor progress of the code. I mean for larger values of N_S, say, 1E10, the running time for the code will be large enough so I would like to monitor how much has it progressed which could be estimated by k*100/N_S and I may print the value at the end of each loop. But, that will not look convenient from representation prespective, as you it will keep onprinting lines after lines of percentage. So I would like to print it as 1% 2%....99% at a single point. – Subhadip Saha Jul 31 '21 at 07:17
  • Does this answer your question? [Python Progress Bar](https://stackoverflow.com/questions/3160699/python-progress-bar) – ti7 Aug 02 '21 at 23:13

2 Answers2

1

tqdm is a popular progress meter for loops, and may work for your case

from tqdm import tqdm

for value in tqdm(my_iterable):
    ...
ti7
  • 16,375
  • 6
  • 40
  • 68
-1
from time import sleep
import sys

for i in range(21):
    sys.stdout.write('\r')
    # the exact output you're looking for:
    sys.stdout.write("[%-20s] %d%%" % ('='*i, 5*i))
    sys.stdout.flush()
    sleep(0.25)
Shuduo
  • 727
  • 5
  • 14
  • Could you please explain, How do we decide the range of "i" here ? – Subhadip Saha Jul 31 '21 at 05:33
  • 'N_S = 100 k = 0 while(k < N_S): k = k + 1 percentage = (k/N_S)*100 print(np.round(percentage, 3)," % ")' – Subhadip Saha Jul 31 '21 at 06:18
  • Sir, could you please teach me how could your procedure be incorporated within this code ? Thanks. – Subhadip Saha Jul 31 '21 at 06:19
  • It's just an example of how to show a progress bar. The value of progress depends on how you measure the compiling's progress. I guess you must compile a big number of files. then you can select when is a percent you decide among some files are processed. Then show the progress bar as above. – Shuduo Jul 31 '21 at 16:04