Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MINGW64 doesn't print during execution

I'm using Git Bash to run my Python scripts on Windows. I noticed that the console doesn't print while my scripts are running. All the strings are printed just when the scripts finish. I read that is a buffer and line break issue. How can I fix it?

like image 931
bodruk Avatar asked Jul 29 '26 13:07

bodruk


2 Answers

I am using MINGW64 on Windows10, and python -u works for me. For example,

   python -u foo.py

From python --help:

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
like image 145
Ted Avatar answered Aug 01 '26 03:08

Ted


I solve this including sys.stdout.flush() after each print().

like image 27
bodruk Avatar answered Aug 01 '26 01:08

bodruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!