# Flush onpartial cout/cerr in jupyter notebook

**URL:** <https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166>\
**Category:** ROOT\
**Tags:** rdataframe, jupyter\
**Created:** [March 21, 2023, 4:40pm UTC](https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166 "2023-03-21T16:40:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiso](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wiso/32/11120_2.png) [@wiso](https://root-forum.cern.ch/u/wiso)\
**Post date:** [March 21, 2023, 4:40pm UTC](https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166/1 "2023-03-21T16:40:17Z")

</div>

I have implemented a simple callback for `OnPartialResult` for RDataFrame. Everything inside a jupyter notebook

```auto
ROOT.gInterpreter.Declare(
    r"""
    void my_callback_(TH1D &h) { std::cerr << (int)h.GetEntries() << std::endl; }
    std::function<void(TH1D &)> my_callback = my_callback_;
    """
)

# ...

df = df.Define("zero", "0.")
histo_counting_all = df.Histo1D(("histo_counting_all", "n entries", 1, 0.0, 1.0), "zero")
histo_counting_all.OnPartialResult(10000, ROOT.my_callback)

```

It works, but the output is printed at the end, not during the processing. Is there a way to force the output to be flushed on the cell output?

* * *

_ROOT Version:_ 6.26/10  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 21, 2023, 7:10pm UTC](https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166/2 "2023-03-21T19:10:56Z")

</div>

Try: `std::cerr << (int)h.GetEntries() << std::endl << std::flush;`

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 21, 2023, 9:41pm UTC](https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166/3 "2023-03-21T21:41:14Z")

</div>

Mmmh I see how this is annoying but I think it comes down to the jupyter kernel implementation.

Maybe @etejedor knows more, if he still gets these pings? 😃

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 4, 2023, 9:41pm UTC](https://root-forum.cern.ch/t/flush-onpartial-cout-cerr-in-jupyter-notebook/54166/4 "2023-04-04T21:41:57Z")

</div>

Closed on April 4, 2023, 9:41pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
