0

How do I set something like pythonunbuffered=1 but for numba? It works fine in terminal, lines get printed sequentially as expected, but in my ipynb it prints many lines at once always.

@numba.njit
def test_print():
    for i in range(100000):
        x = sum([j for j in range(i)])
        if i % 10000 == 0:
            print("step")
            print(x)

test_print() 
Adam
  • 1,724
  • 4
  • 21
  • 31
  • usually no prints show until I interrupt the cell – Adam Mar 03 '23 at 19:15
  • You certainly need a flush (but AFAIK you cannot call it from a Numba njitted function unless you switch to the object-mode which is experimental and sometimes cause a crash so far). You can split the computation in chunks. Printing things in a middle of a computing kernel is a bad idea anyway (for both software engineering and performance). – Jérôme Richard Mar 03 '23 at 21:34

0 Answers0