1

I have a Windows 10 python script that I usually run using the following command:-

python -u my_python_application.py

The -u option is used to force stdin, stdout and stderr to be totally unbuffered. This gives my application an instantaneous feel, and without it there is a delay where data is logged after the operation occurs.

I am now trying to create an executable through Pyinstaller. So far everything is working as expected and I can generate an executable which I can run without any major issues. However, the generated executable does not have the unbuffered stdio option, and as a result my application is not as instantaneous/responsive as its non-executable form. So my question is: Is there anyway to force stdio to be totally unbuffered when using Pyinstaller?

I have found similar unanswered posts here:-

I am using Python v2.7.13 and Pyinstaller v3.6 on a Windows 10 machine.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72

1 Answers1

0

This is more of a work around than a fix, but the way I was able to get around this was by using the option flush=True when calling the print statement. In other words, I replaced all print statements in my application with a new function called app_print() as follows:-

#Do something
app_print("printing a generic string")

then I defined app_print to always flush the stdio:-

def app_print(sting):
    print(string, flush=True)

This fixed my problem and the resulting executable now has an instantaneous feel similar to how the original python script did.

More links about this:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72