473,769 Members | 6,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2621
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*******@Hotpo p.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*****@holden web.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
2596
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 about server certificate authenticity, which presumably is what urllib2 is blocking at. How can I prepare my code for this eventuality and ensure it doesn't block?
2
6118
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 #80 and line # 38 are the first line offenders. --> --> -->
5
7410
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. here's my pyscript:
4
3737
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 individuals within that subnet accessing web pages independently. I need the functionality of urllib2 because there will be redirects and other HTTP-type functions to implement. It would be nice if I could create (and bind) sockets myself and then...
2
3498
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 managed). I create a server socket, and then listen on it. I then accept a new connection from that server socket. If I now close the server socket, it also closes the accepted connection as well, automatically. This feels stupid.
4
2769
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 client socket connection. If I close the listener socket, will the client sockets also shut down? Or do I need to manually shut these down as well?
4
2592
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 have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with.
1
5760
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 url="http://localhost/private/file" #proxy set up
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.