473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

pep 3116 behaviour on non-blocking reads

In the RawIOBase class I read the following:

..read(n: int) -bytes

Read up to n bytes from the object and return them. Fewer than n
bytes may be returned if the operating system call returns fewer
than n bytes. If 0 bytes are returned, this indicates end of file.
If the object is in non-blocking mode and no bytes are available,
the call returns None.
I would like the developers to reconsider and return 0 bytes when no
bytes are available and let None indicate end of file.

The reason is that this can lead to clearer code that will work
independant of the blocking mode of the stream.

Consider a consumer that just has to treat each byte. Then with
the current choice the code will look something like the following
(assuming pep 315 is implemented)
| do:
| buf = stream.read(nr)
| while buf != "":
| if buf is not None:
| for b in buf:
| treat(b)
If what the method returns follows my proposal, the code to do the same
would look something like the following:
| do:
| buf = stream.read(nr)
| while buf is not None:
| for b in buff:
| treat(b)
The advantage with my propsal is that in a lot of cases an empty buffer
can be treated just the same as a non-empty one and that is reflected
in the return values of my proposal.
--
Antoon Pardon
Aug 9 '07 #1
1 1083
Antoon Pardon wrote:
I would like the developers to reconsider and return 0 bytes when no
bytes are available and let None indicate end of file.
That would be a major departure from the way IO has
always been handled before in Python, which follows
the Unix model.

Also, only code that deals with non-blocking streams
will ever get None, and such code is relatively rare,
so most code won't have to worry about the None case.

Even when dealing with a non-blocking stream, usually
there will be some other way (such as select) used to
determine when there is something to be read from a
stream, and it won't be read otherwise. In that case,
the code *still* won't ever see a None.

So I think the PEP has it right.

--
Greg
Aug 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: marbac | last post by:
Hi, i heard a lot about "undefined behaviour" in this and other newsgroups dealing with c/c++. Is there a list where all cases with undefined behaviour in C++ are listed? regards marbac
1
by: JKop | last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non- portable"? signed main() { signed char chedder = 130; } Relevant information:
4
by: Mark Stijnman | last post by:
A while ago I posted a question about how to get operator behave differently for reading and writing. I basically wanted to make a vector that can be queried about whether it is modified recently...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
31
by: grid | last post by:
Hi, A collegue of mine is of the opinion that the behaviour of the following program is defined,but I am a little apprehensive. #include<stdio.h> #include<string.h> int main() { char *c;
3
by: Carlo Capelli | last post by:
I found a change in the following code, that behaved correctly in VC++ 6. #include <strstream> using namespace std; void main() { char x; ostrstream(x, 100) << "pippo" << "pluto" << ends;...
4
by: | last post by:
I have earlier used an HttpModule that did URL rewrites on the BeginRequest event. Now I am trying to use the same module in a different application on a new and upgraded machine (winxp sp2). ...
24
by: temper3243 | last post by:
Hi, Many people have used this code in my project. It works because b is using the extra memory for other 4 variables.I access obj max. well here are a few questions 1) Where does it fail. I...
1
by: sachingoel82 | last post by:
Hi All, I find following C++ behaviour regarding temporary objects quite contradictory. Consider this: class A { ... public:
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.