Issue 723312: ability to pass a timeout to underlying socket (original) (raw)

Created on 2003-04-17 19:03 by mattruss, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
timeout.diff skip.montanaro,2007-02-11 18:14
Messages (12)
msg43401 - (view) Author: Matthew Russell (mattruss) Date: 2003-04-17 19:03
this patch superceeds an earlier one i posted (#714592) - a bit *too* enthusiastic am afraid (sorry!) classes in modules such as httplib, ftpplib do not currently allow an easy way to take advantage of the new socket timeout feature in 2.3. This patch provides that abilty though one additonal class in socket.py ( socket.NetworkConnection ) and accompying test in test_socket.py (basic though the test is :-s ) As an extra benifit, the patch removes duplicate code, as each connect method in the main class of most modules (FTP, HTTPConnection, Telnet, POP3 etc) are copies of each other. The modules that use sockets are: * ftplib * httplib * telnetlib * poplib * urllib * imaplib * nntplib * xmlrpclib Of these I have only been able to easily refactor NetworkConnection into httplib, ftplib, telnetllib, poplib and smtplib. I did look to see if there were any unittests for theese modules in .Lib/test but found none (? - I appologise if there are some, i am new to the library tests) I did however check that the test() [like] methods at the bottom of each of the afore mentioned modules worked. thanks for your advice again Skip :o) Matt
msg43402 - (view) Author: Matthew Russell (mattruss) Date: 2003-04-20 23:20
Logged In: YES user_id=737261 Errata: i forgot to mention urlllib2 as modules affected. the line above starting "The modules that use sockets are: " should really read: "classes in the modules stated below would benifit from the ability pass timeouts:"
msg43403 - (view) Author: Grégoire Weber (gregweb) Date: 2005-01-12 13:52
Logged In: YES user_id=812601 Just lobbying: It would be nice to have that on board in futire python versions. Would this be possible in python 2.4.1? I need timeouts for xmlrpclib and subclassed xmlrpclib.Transport for my needs. But nevertheless it would be nice to have that in python 2.4.1. Thanks! Gregoire
msg43404 - (view) Author: zeidler (zeidler) Date: 2005-09-28 14:22
Logged In: YES user_id=1082576 perhaps to add a little emphasis: i'd really like to see that patch included into one of the next releases too. i was just going to submit my own, much much simpler version of adding a socket timeout in httplib.py, but matt's patch is a much better way to do this... we're using xml-rpc a lot over here, and the default timeouts are just way too long to keep up a decent user interaction in case of server problems. so, we'd really appreciate this becoming part of the distro! ;) thanks & good job matt, andi
msg43405 - (view) Author: Anthony Baxter (anthonybaxter) (Python triager) Date: 2005-10-01 03:39
Logged In: YES user_id=29957 Just a quick note - this patch might be accepted for 2.5, but it's not suitable for 2.4.x - once a major release is done, subsequent minor releases (2.3.x, 2.4.x) are bugfix-only. No new features are acceptable. For more on this, see http://www.python.org/peps/pep-0006.html
msg43406 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-04-14 16:09
Logged In: YES user_id=21627 mattruss, are you interested in forward-porting it to 2.5? If that gets done before the beta release, please assign it to me for review.
msg43407 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-02-10 18:57
Here's an updated patch. Tests pass. There's no documentation for socket.NetworkConnection or for the API changes to smtplib, httplib, telnetlib, poplib or ftplib. File Added: timeout.diff
msg43408 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-02-11 16:24
New patch with minor tweaks. Added doc changes. File Added: timeout.diff
msg43409 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-02-11 18:11
*argh* one minor tweak too many... File Added: timeout.diff
msg43410 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-02-11 18:14
Jeez, I can be an idiot sometimes... Working on two patches in the same sandbox. File Added: timeout.diff
msg43411 - (view) Author: John J Lee (jjlee) Date: 2007-02-25 16:43
Looks good. I can't write tests right now, but just reading the code: I don't see a path in socket.NetworkConnection.connect() in which "if sock is None" is ever true. And what happens if creating a new socket object raises an exception (e.g. if too many file descriptors are open)? Then socket may be undefined, and will certainly not be None. I think it needs a sock = None before the loop, and also in the except: suite immediately before the continue statement. Some debug output in httplib has been lost (and maybe in the other modules). This is really very useful, so I think it should be preserved. In ftplib, FTP.makeport() should also use socket.NetworkConnection . PEP 8 nits: Use of thisStyleOfName, e.g. networkConnection Use of two-argument raise, e.g. raise socket.error, msg -- replace with raise socket.error(msg)
msg43412 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2007-03-29 18:15
After a lot of discussion in python-dev, I added a create_connection() to socket.py module, to which a timeout can be passed. Then, used this new function from httplib, poplib, smtplib, telnetlib, and ftplib, so I'll close this patch. I'm putting this as "accepted" because all my work started from here, and even not applied as is, I used it a lot . Regards,
History
Date User Action Args
2022-04-10 16:08:12 admin set github: 38322
2003-04-17 19:03:29 mattruss create