How to flush stdout in no console app?

260 views
Skip to first unread message

wryb...@gmail.com

unread,
Jun 16, 2008, 7:47:17 AM6/16/08
to PyInstaller
I've noticed if I have print statements in my Python app, the compiled
console-less version will error out with a "bad file descriptor" error
after about 240 lines. I thought I'd be able to solve this with a
sys.stdout.flush() call, but oddly, that works fine in the regular .py
file, but when run in a console-less Pyinstaller app, it returns the
"bad file descriptor" error immediately.

The way I've been handling this is to be very careful about including
print statements in any project that I'll be converting to a no
console .exe file, but I'd love to be able to flush stdout every now
and again so I can still use print statements.

Is there some way to do this?

Thanks for any help.

Phil Mayes

unread,
Jun 16, 2008, 10:39:45 PM6/16/08
to PyIns...@googlegroups.com

I use print statements to generate a trace file with no problems. Maybe
file vs. console explains the difference, but it might also be because I
write unbuffered:

# param3==0 makes stdout unbuffered
sys.stderr = sys.stdout = open(fname, 'w', 0)
print '%s trace started on %s (frozen=%s)' % (identity.IDENTITY,
time.ctime(time.time()), hasattr(sys, 'frozen'))
print utils.GetOS()

HTH, Phil

wryb...@gmail.com

unread,
Jun 16, 2008, 10:47:29 PM6/16/08
to PyInstaller
That's an interesting solution, simply writing to a file... I suppose
I could do this, but this comes up for me so often that I'd love to
simply know how to flush stdout.

Reply all
Reply to author
Forward
0 new messages