Message135347
When upgrading from Python 3.1 to Python 3.2 I noticed that when my program closed it printed out a non-consequential AttributeError Exception. My program had a custom class that replaced stdout and stderr for use in a piped program (it flushed the buffer after every print statement)
I was able to reduce my code down to this simple test case that will reproduce the issue. Note that this doesn't show up in idle.
code:
import sys
from time import sleep
import subprocess
python31loc = r"C:\python31\python.exe";
python32loc = r"C:\python32\python.exe";
myname = "attributeError.py";
class FlushFile(object):
#"""Write-only flushing wrapper for file-type objects."""
def __init__(self, f):
self.f = f
try:
self.encoding = f.encoding;
except:
pass;
def write(self, x):
self.f.write(x)
self.f.flush()
# sets stdout and stderr to autoflush
def setAutoFlush():
if sys.__stdout__ != None: # will be None in IDLE
sys.stdout = FlushFile(sys.__stdout__);
sys.stderr = FlushFile(sys.__stderr__);
if __name__ == "__main__":
setAutoFlush();
if(len(sys.argv) == 1):
print("Testing python 3.1");
output = subprocess.check_output("%s %s -output" % (python31loc, myname));
print("Should see no error");
print("Testing python 3.2");
output = subprocess.check_output("%s %s -output" % (python32loc, myname));
print("Should see no error");
sleep(16);
Output:
Testing python 3.1
Should see no error
Testing python 3.2
Exception AttributeError: 'flush' in <__main__.FlushFile object at 0x00C347F0> i
gnored
Should see no error |
|
Date |
User |
Action |
Args |
2011-05-06 17:44:37 | Jimbofbx | set | recipients:
+ Jimbofbx |
2011-05-06 17:44:37 | Jimbofbx | set | messageid: <1304703877.7.0.898555574271.issue12020@psf.upfronthosting.co.za> |
2011-05-06 17:44:36 | Jimbofbx | link | issue12020 messages |
2011-05-06 17:44:36 | Jimbofbx | create | |
|