py3k buffered IO - flush() required between read/write?
Hey all, Apologies if this is a dumb question (self = Python noob), but under py3k is it necessary to flush() a file between read/write calls in order to see consistent results? I ask because I have a case under Python 3.2 (r32:88445) where it does appear to be, on both Gentoo Linux and Windows Vista. I've naturally read http://docs.python.org/py3k/library/io.html and http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files but could find no reference to such a requirement. PEP 3116 suggested this might not be required in py3k and the implementation notes in bufferedio.c state "BufferedReader, BufferedWriter and BufferedRandom...share a single buffer...this enables interleaved reads and writes without flushing." Which seemed conclusive but I'm seeing otherwise. I have a test case, which is sadly rather long: http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated from some rather more complex code I'm working on, in order to reproduce the issue in isolation. Any advice and/or flames appreciated. All the best, -eg. -- http://mail.python.org/mailman/listinfo/python-list
Re: py3k buffered IO - flush() required between read/write?
On 11/05/2011 19:24, Terry Reedy wrote:
writing and reading. If you want others to look at this more, you should
1) produce a minimal* example that demonstrates the questionable
behavior, and 2) show the comparative outputs that raise your question.
Thanks for a quick response. Perhaps I was being unclear - in py3k,
given the following code and assuming no errors arise:
> f = open("foo", "w+b")
> f.write(b'test')
> f.seek(0)
> print(f.read(4))
What is the printed result supposed to be?
i) b'test'
ii) never b'test'
iii) platform dependent/undefined/other
All the best,
-eg.
--
http://mail.python.org/mailman/listinfo/python-list
Re: py3k buffered IO - flush() required between read/write?
With 3.2 on winxp, that is what I get with StringIO, text file, and bytes file (the first two with b's removed). I would expect the same on any system. If you get anything different, I would consider it a bug Thanks Terry, you're entirely right there; I trimmed down my test case, asked for confirmation and have reported it as http://bugs.python.org/issue12062. Noted here in case anyone else trips over it. -- http://mail.python.org/mailman/listinfo/python-list
Re: py3k buffered IO - flush() required between read/write?
On 12/05/2011 20:44, Terry Reedy wrote: I want people to know that with a simple, minimal, easy to run and reproduce and think about test case posted, more info, more test cases, and probable fixes were posted within an hour. (Fixes are not always that quick, but stripping away irrelevancies really helps speed the process.) A very good point. I'm extremely impressed with the speed and deftness which the bug was handled once raised. Hats off to the people involved. I should have posted a short test case initially, but I knew it would take some time for me to produce and didn't want to go that far if it was clear to everyone but me that flushes were required by design :) Thanks again, -eg. -- http://mail.python.org/mailman/listinfo/python-list
Re: List of WindowsError error codes and meanings
On 20/05/2011 18:56, Andrew Berg wrote: This is probably somewhat off-topic, but where would I find a list of what each error code in WindowsError means? Assuming it's a Win32 error code, winerror.h from the Platform SDK holds the answer. One version is linked below, it's in theory out of date (2003) but all the best known codes are present. http://msdn.microsoft.com/en-us/library/ms819773.aspx http://msdn.microsoft.com/en-us/library/ms819775.aspx For example, "WindowsError [error 5] Access is denied" matches ERROR_ACCESS_DENIED (5L). HRESULTS may also crop up (e.g. E_FAIL, 0x80040005) which are harder to list exhaustively since subsystems and COM components may roll their own codes of various sorts; but common ones are present in winerror.h. All the best, -eg. -- http://mail.python.org/mailman/listinfo/python-list
Re: List of WindowsError error codes and meanings
Andrew Berg writes: Since Python 2.5, the errno attribute maps the Windows error to error codes that match the attributes of module errno. Good point, I completely misread that. At least the Windows error code is still available as the winerror attribute. As an aside - call me stupid, but I don't quite follow the purpose of that errno mapping. Surely if the error number can be mapped successfully then the error isn't Windows specific and an OSError should logically be thrown instead? And if it can't be mapped successfully then errno will never be valid so the mapping is pointless? I guess if the mapping is imprecise then it makes some sense as errno is a convenience to avoid people having to grasp the meaning of the many and various winerror.h values. So perhaps I've answered my own question. -- http://mail.python.org/mailman/listinfo/python-list
