[Python-Dev] timeoutsocket.py

Timothy O'Malley timo@alum.mit.edu
Sat, 04 May 2002 16:15:01 -0400


That's awesome that you put the timeout functionality into the C-level
socket module.  I'd vote that it is "The Right"(tm) way to include this
feature in the standard library.  You guys rock!

I couldn't get to the web site you indicated, so pardon this question
if I could have found the answer on-line somewhere.

How did you handle the _fileobject class in the standard socket.py?
The version in Python-2.2 will lose data if the underlying socket raises
an exception during a read() or readlines().  Basically, these two
routines use a local variable to store the incoming data -- and that
local variable will go out of scope after the exception during recv().

I believe that the TimeoutFile class in the socket.py version I thew
together fixes this issue.  Of course, you may have already noticed
and fixed this, too.

Again, very awesome!


"Everything I did in life that was worthwhile I caught hell for."
 - former U.S. Supreme Court Chief Justice Earl Warren

> From: Bernard Yue <bernie@3captus.com>
> Date: Fri, 03 May 2002 01:49:02 -0600
> To: "Timothy O'Malley" <timo@alum.mit.edu>
> Cc: skip@pobox.com, python-dev@python.org, mgilfix@eecs.tufts.edu
> Subject: Re: [Python-Dev] timeoutsocket.py
> Timothy O'Malley wrote:
>> hola.
>> I've taken a whack at option #1 (grand unification of socket and
>> timeoutsocket).
>> It's larger than I'd prefer to send in email.  If you are interested:
>>   http://www.timo-tasi.org/python/socket.py
>> --
>> TimO
> Tim, this is a complete rewrite of timeoutsocket.py.  It is quite an
> effort :)
>> 1.  Shall we merge socket.py and timeoutsocket.py?
>> It certainly is possible to merge TimeoutSocket and _socketobject.
>> If the merge was done in a straightforward manner, then every TCP
>> socket would use Python code (instead of C code) for recv() and
>> send() methods.  Some might consider this an unacceptable performance
>> hit.
> I agree on the performance issue.  Over the past two weeks, Michael
> Gilfix and I moved ahead with the implementing of timeout socket in C
> level.  Michael translates what you've done in timeoutsocket.py and put
> it into socket.c.  So far we did nothing to TimeoutFile.  The proposed
> patch is basically done (except for the test case).  You can find it on
> http://www.3captus.com/Downloads/.
> We are now working on the test case for connect() and sendfoo().
> Currently, test for connect() is done by trying a timeout connect to an
> external site (same to what you've done).  However, we wanted to remove
> the external dependency on standard python test suit.  So far no luck of
> make it working, and I cannot make sendfoo() to raise timeout error at
> all.
> Would you like to help us with the test?
> Bernie
> -- 
> There are three schools of magic.  One:  State a tautology, then ring
> the changes on its corollaries; that's philosophy.  Two:  Record many
> facts.  Try to find a pattern.  Then make a wrong guess at the next
> fact; that's science.  Three:  Be aware that you live in a malevolent
> Universe controlled by Murphy's Law, sometimes offset by Brewster's
> Factor; that's engineering.
>               -- Robert A. Heinlein