[Python-bugs-list] [ python-Bugs-706263 ] print raises exception when no console available

SourceForge.net noreply@sourceforge.net
Thu, 20 Mar 2003 01:19:35 -0800


Bugs item #706263, was opened at 2003-03-19 14:05
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=706263&group_id=5470

Category: Windows
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Submitted By: Alexander Miseler (amiseler)
Assigned to: Mark Hammond (mhammond)
Summary: print raises exception when no console available

Initial Comment:
platform: win2k
testet with: 2.2.2   2.3a1   2.3a2

the test case works fine when the script is run with
python.exe. with pythonw.exe an exception is raised
after printing 4096 bytes. the exception is rather
obscure but the bytecount suggests a buffer overflow.

print (or to be more exact sys.stdout.write) should be
a noop when there is no console.


test case:
import traceback
counter = 0
try:
	for counter in range(100000):
		print 'a',
	success_file = open('success.txt', 'w')
	success_file.write('Bytes printed: %d\n' % (counter*2))
	success_file.close()
except:
	error_file = open('error.txt', 'w')
	error_file.write('Bytes printed before exception was
raised: %d\n' % (counter*2))
	traceback.print_exc(100, error_file)
	error_file.close()


output:
Bytes printed before exception was raised: 4096
Traceback (most recent call last):
  File "test_case.py", line 5, in ?
    print 'a',
IOError: [Errno 9] Bad file descriptor


----------------------------------------------------------------------

>Comment By: Alexander Miseler (amiseler)
Date: 2003-03-20 10:19

Message:
Logged In: YES 
user_id=693638

then please throw a meaningful exception at first byte
written, not an obscure exception after 4096 bytes written.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-03-20 05:17

Message:
Logged In: YES 
user_id=31435

I can swing either way on this, or even a third:  open text 
files stdout.txt and stderr.txt in the current directory then.  
That's really aiming at a different irritation, though, that 
tracebacks end up in the bit bucket by default under 
pythonw.

BTW, making stdout and stderr /dev/null workalikes is 
least attractive to me (nobody would write to stdout or 
stderr *intending* the output be lost).  I'm (barely) OK with 
letting it stay as it is, because that just reflects Windows 
reality.

----------------------------------------------------------------------

Comment By: Mark Hammond (mhammond)
Date: 2003-03-20 00:51

Message:
Logged In: YES 
user_id=14198

I struck this years ago, but was in a quandry.  On one hand,
sys.stdout *is* invalid, and I see no reason why Python
should mask these errors.  There may be real applications
where this failure *must* be reported to the program rather
than simply consumed.

However, I see the point that print is so basic that is
should never fail.  To my mind, the first point outweighs
the first, and the problem is fairly simply solved (see if
sys.stdout is invalid, and if so, open a file and set it to
that).

So I am afraid that, no, I don't give a rats <wink>.  Unless
conivenced otherwise (ie, by Tim or Guido) I will close this
as "not a bug" in a week or so.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-03-19 18:18

Message:
Logged In: YES 
user_id=31435

Mark, give a rip <wink>?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=706263&group_id=5470