Show progress in Python from underlying C++ process
<p>I have a C++ program that runs for a long time and performs lots (e.g. 1,000,000) of iterations. Typically I run it from Python (usually Jupyter Notebook). I would like to see the a progress from the C++ program. Is there a convenient way to do it? Perhaps to link it to a Pythonic progress bar library, e.g. tqdm?</p>

<p>Disclaimer, I'm codeveloper of tqdm.</p>

<p>I see 3 solutions :</p>

<ul>
<li><p>Either the cpp lib regularly calls back to python like after processing each row of a matrix (as pandas does) and then you can use a Python progress bar like tqdm, just like for any other common python loop. The loop won't be updated at each iteration but at each callback, so it's not really real-time but if the cpp lib is fast, you won't notice anything. See the submodule tqdm_pandas for example, it works exactly like that. </p></li>
<li><p>Either the cpp lib does all the work without any callback until the end (this maximizes performances, callbacks to Python are huge slowdowns), then you need to use a cpp progress bar inside your cpp lib, as you cannot use a python one (since it will never be called until the end). There is an <a href="https://github.com/tqdm/tqdm.cpp" rel="nofollow">official cpp port of tqdm</a> in development, this might fit your needs.</p></li>
<li><p>Last case is if your cpp program is not a linked lib but rather a standalone program that can be run from command-line. In this case, tqdm has facilities to interface with such programs as long as your cpp program can output something. See the readme about it, it works already well for gzipping and other commin Unix commands. </p></li>
</ul>

python subprocess progress-bar jupyter-notebook tqdm