5

I have a Py3.x GUI app I've been building with Gooey. The app is fully functional, and the GUI works as intended, with the exception of the built-in console/terminal receiving buffered output.

This isn't an issue if I run the .py file with pythonw -u script.py, however I'm now trying to bundle/freeze the tool in to a .app. The bundling process has worked, but there is still the issue of buffered output when the app is opened.

So far, I have found the following, but nothing I've tried has worked:

  • Several threads have suggested using flush=True with print() to write on each call, but logging - which is what I'm interested in here - has no such complementary flag. Consequently, the various monkey-patching solutions in that thread are also no use to me (with the caveat that I don't know the internals of logging well, so perhaps there is a similar approach applied to a logger that could work? Gooey itself, and the packaging process outputs much more logging info than my own calls, and that is still buffered, so it seems that 'global unbuffering' is what's really needed anyway.

  • This thread offers a number of approaches. Indeed, re-opening sys.stdout with a 0 buffer size is the suggested approach, however there is conflicting opinion in the first thread about whether it still works on Python 3 in light of PIP 3116, and certainly in my hands, use of

    nonbuffered_stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
    sys.stdout = nonbuffered_stdout
    

    seems to break the .app altogether.

  • Trying to 'inject' a -u or PYTHONUNBUFFERED=1 into the shebangs also does not seem to work (in this case on MacOS), with or without -S.


So, TL;DR:

How can unbuffered output be achieved in Python 3.x, when the script is not being explicity invoked with python3 -u ?

I'm still trying to put together a MWE, but the use of gooey combined with the packaging process is making this a bit difficult.

7

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.