Ask Your Question
0

printing far later than the actual print statement

asked 2018-12-10 15:50:23 +0100

Artuur gravatar image

I have some code in a jupyter notebook which takes some time to run. When I run it, it does multiple calculations in which between there are print statements such that I can see certain results. Now the thing is that it sometimes chooses to wait with revealing the results of print statements. With this I mean:
My code first prints some results, then 20 seconds later it prints a lot more result. But I added the current time to all my print statements, which reveals that most of them could have been shown less than a second after the first results were printed. This makes sense since it finishes off with calculating a groebner basis, which takes longer than any of the other calculations, but I don't know why it wouldn't show any of the print statements which are done before the groebner basis calculations start.
Is there a way to make certain that it immediately prints instead of waiting until a later step of the program?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-12-11 10:08:19 +0100

slelievre gravatar image

For efficiency, print instructions send output to a buffer, and the printing can happen later.

To force printing immediately, try flushing the output.

See https://duckduckgo.com/?q=python+flush.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-12-10 15:50:23 +0100

Seen: 519 times

Last updated: Dec 11 '18