473,387 Members | 1,705 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,387 software developers and data experts.

urllib2 - closing sockets

I recently noted that urllib2.urlopen(...) for http:// urls
does not make an explicit call to close the underlying
HTTPConnection socket once the data from the socket is read.

This might not be required since the garbage collector will
close & collect open sockets that are not closed, but it might
cause the system to run out of socket memory if there are
multiple threads, each opening a socket and the gc not running
in between.

This specifically happens in my HarvestMan program which uses
multiple threads to achieve fast offline web downloads.

A patch to fix this in urllib2.py would be nice.

Thanks

-Anand
Jul 18 '05 #1
3 2603
Anand Pillai wrote:
I recently noted that urllib2.urlopen(...) for http:// urls
does not make an explicit call to close the underlying
HTTPConnection socket once the data from the socket is read.

This might not be required since the garbage collector will
close & collect open sockets that are not closed, but it might
cause the system to run out of socket memory if there are
multiple threads, each opening a socket and the gc not running
in between.

This specifically happens in my HarvestMan program which uses
multiple threads to achieve fast offline web downloads.

A patch to fix this in urllib2.py would be nice.

Thanks

-Anand


In which case you'd be well advised to add this as a bug report on
Sourceforge, as that is the only way to guarantee it will come to (and
stay in) the developers' attention.

It isn't that hard to do.

regards
Steve
Jul 18 '05 #2
py*******@Hotpop.com (Anand Pillai) writes:
I recently noted that urllib2.urlopen(...) for http:// urls
does not make an explicit call to close the underlying
HTTPConnection socket once the data from the socket is read.

This might not be required since the garbage collector will
close & collect open sockets that are not closed, but it might
cause the system to run out of socket memory if there are
multiple threads, each opening a socket and the gc not running
in between.

This specifically happens in my HarvestMan program which uses
multiple threads to achieve fast offline web downloads.
Does this cause trouble in your app?

I tried using urllib2 with threads a while back, and failed miserably.
Do you reckon the problem you've found could cause deadlock? Seems
unlikely, but I was at the point of having to read the threading
module's code to get any further with my deadlock bug, so I'm
clutching at straws...

A patch to fix this in urllib2.py would be nice.


if-wishes-were-horses-then-beggars-would-ride-<wink>-ly y'rs
John
Jul 18 '05 #3
Steve Holden <sh*****@holdenweb.com> writes:
[...]
A patch to fix this in urllib2.py would be nice.
Thanks
-Anand


In which case you'd be well advised to add this as a bug report on
Sourceforge, as that is the only way to guarantee it will come to (and
stay in) the developers' attention.

It isn't that hard to do.


Steve's right that it's not hard to do.

Unfortunately, since people who actually fix bugs (ie. Martin von
Loewis <0.8 wink>) are in short supply, that doesn't guarantee that it
will come to anybody's attention. Of course, you have a *vastly*
higher chance of getting a bug fixed if you provide a patch with
appropriate docs and test code to go with it.
John
Jul 18 '05 #4

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

Similar topics

2
by: Derek Fountain | last post by:
I just tried this: >>> import urllib2 >>> urllib2.urlopen( "https://passenger.ssc.com/~dmarti/contrib-faq/" ) It sits forever. Loading that URL in a normal browser gets me a popup asking...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
5
by: Pascal | last post by:
Hello, I want to acces my OWA (Outlook Web Acces - http Exchange interface) server with urllib2 but, when I try, I've always a 401 http error. Can someone help me (and us)? Thanks. ...
4
by: Dan | last post by:
Does anybody know how to control the source IP address (IPv4) when using the urllib2 library? I have a Linux box with several IP addresses in the same subnet, and I want to simulate several...
2
by: Lenard Gunda | last post by:
Hi, I have the following problem when I am working with sockets in C#. I do not remember running into the same problem some while ago, when working with sockets from C++ (using native code, not...
4
by: Funke | last post by:
Assume that in C#, I create a server socket (listener) and code to start new threads with each connection using BeginAccept(). After some time, I have three threads running, each with their own...
4
by: dumbkiwi | last post by:
I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I...
1
by: Alessandro Fachin | last post by:
I write this simply code that should give me the access to private page with htaccess using a proxy, i don't known because it's wrong... import urllib,urllib2 #input url...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.