[Python-Dev] Getting an optional parameter instead of creating a socket internally (was: Re: stdlib socket usage and " keepalive" )

Jesus Cea jcea at jcea.es
Tue Apr 13 01:19:40 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/13/2010 12:47 AM, Antoine Pitrou wrote:
> Jesus Cea <jcea <at> jcea.es> writes:
>>
>> PS: "socket.setdefaulttimeout()" is not enough, because it could
>> shutdown a perfectly functional connection, just because it was idle for
>> too long.
> 
> The socket timeout doesn't shutdown anything. It just puts a limit on how much
> time recv() and send() can block. Then it's up to you to detect whether the
> server is still alive (for example by pinging it through whatever means the
> application protocol gives you).

A regular standard library (let say, poplib) would abort, after getting
the timeout exception.

>> 4. Modify client libraries to accept a new optional socket-like object
>> as an optional parameter. This would allow things like transparent
>> compression or encryption, or to replace the socket connection by
>> anything else (read/write to shared memory or database, for example).
> 
> This could be useful too.

I have been thinking about this for years. Do you actually think this
could be formally proposed?.

What bugs me is that the socket creation is deep inside the stdlibs. You
can not control it easily (I have overloaded socket.socket() in the past
for controlling the number of concurrent connections to servers, for
instance, or providing encryption), and it is difficult to test.

If these stdlib methods could accept an optional parameter instead of
creating the socket internally, test is trivial, and you can reuse the
lib to access the service via an arbitrary object (this weekend I just
tunneled TCP/IP via DNS requests/answers, shame on you, airport wifi
hotspots!).

- -- 
Jesus Cea Avion                         _/_/      _/_/_/        _/_/_/
jcea at jcea.es - http://www.jcea.es/     _/_/    _/_/  _/_/    _/_/  _/_/
jabber / xmpp:jcea at jabber.org         _/_/    _/_/          _/_/_/_/_/
.                              _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQCVAwUBS8Oqi5lgi5GaxT1NAQKPpgP/S2V3umt4SpOw+Epxtj3/oxEFcQuh3s1z
WNvS59+qY6IK0+/MCvxDiAYliGbj8PY76lXmRodJOzwVFe7uPzLhq4h3gBBv0zXs
KvBHdyL5fnp4UEId89L7+SqejgAfpJk3GXYwAnpLyF5iQzaiYzp0rNDOuSBCeAmW
jFjzjMMZznQ=
=cFb/
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list