Hi all,
is there a way to modify the time a call of
urllib.open(...)
waits for an answer from the other side? Have a tool
which automatically checks a list of websites for
certain content. The tool "hangs" when one of the
contacted websites behaves badly and "never" answers...
Thanks and regards
-stefan- 11 2534
Stefan Palme wrote:
is there a way to modify the time a call of
urllib.open(...)
waits for an answer from the other side? Have a tool
which automatically checks a list of websites for
certain content. The tool "hangs" when one of the
contacted websites behaves badly and "never" answers...
I believe this can only be set globally:
import socket
socket.setdefaulttimeout(seconds)
Peter
Uuuh this is no solution for me, because the
website-checking tool is part of a very very big
application running in an application server, so
globally setting the timeout may break a lot of
other things...
But when there is a "default timeout" (as indicated by
the method name) - isn't there a "per-socket timeout"
too?
-stefan-
I believe this can only be set globally:
import socket
socket.setdefaulttimeout(seconds)
Peter
Stefan Palme wrote:
(top-posting undone)
[Peter]
>I believe this can only be set globally:
import socket socket.setdefaulttimeout(seconds)
[Stefan]
Uuuh this is no solution for me, because the
website-checking tool is part of a very very big
application running in an application server, so
globally setting the timeout may break a lot of
other things...
But when there is a "default timeout" (as indicated by
the method name) - isn't there a "per-socket timeout"
too?
Yes, but it isn't as easily available...
Perhaps you find some ideas here: http://mail.python.org/pipermail/pyt...ry/070897.html
Peter
>>[Peter]
>>I believe this can only be set globally:
import socket socket.setdefaulttimeout(seconds)
[Stefan] ... But when there is a "default timeout" (as indicated by the method name) - isn't there a "per-socket timeout" too?
[Peter]
Yes, but it isn't as easily available...
Perhaps you find some ideas here:
http://mail.python.org/pipermail/pyt...ry/070897.html
Thanks, will have a look at this.
Regards
-stefan-
Stefan Palme wrote:
>>>[Peter] I believe this can only be set globally:
import socket socket.setdefaulttimeout(seconds)
[Stefan] ... But when there is a "default timeout" (as indicated by the method name) - isn't there a "per-socket timeout" too?
[Peter] Yes, but it isn't as easily available...
Perhaps you find some ideas here:
http://mail.python.org/pipermail/pyt...ry/070897.html
Thanks, will have a look at this.
This has recently been discussed on python-dev. It's likely that certain
libraries will acquire a timeout keyword argument in the next release,
but only if someone is concerned enough to develop the appropriate
patches - the principle appears to be accepted.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007
Stefan Palme <kl*****@hora-obscura.dewrites:
is there a way to modify the time a call of
urllib.open(...)
waits for an answer from the other side? Have a tool which
automatically checks a list of websites for certain content. The
tool "hangs" when one of the contacted websites behaves badly and
"never" answers...
Other than by using socket timeouts, at least in Un*x, you can also
use signal.alarm. You can only have one OS-provided alarm pending at
a time, so if you want multiple overlapping timeouts you have to
schedule them yourself with a single alarm.
Steve Holden <st***@holdenweb.comwrites:
[...]
This has recently been discussed on python-dev. It's likely that
certain libraries will acquire a timeout keyword argument in the next
release, but only if someone is concerned enough to develop the
appropriate patches - the principle appears to be accepted.
I didn't read the recent python-dev thread, but ISTM this has been
true since the socket timeout feature was added (Python 2.3?).
Apparently so far nobody wanted it enough to actually implement it.
John
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
Stefan Palme <kl*****@hora-obscura.dewrites:
is there a way to modify the time a call of
urllib.open(...)
waits for an answer from the other side? Have a tool which
automatically checks a list of websites for certain content. The
tool "hangs" when one of the contacted websites behaves badly and
"never" answers...
Other than by using socket timeouts, at least in Un*x, you can also
use signal.alarm. You can only have one OS-provided alarm pending at
a time, so if you want multiple overlapping timeouts you have to
schedule them yourself with a single alarm.
Note that neither of these is guaranteed to time out urllib.open(),
though usually they will.
Another way to solve the underlying problem is not to try to time out
the network operation(s) at all, but to use threads or non-blocking
sockets (e.g. using Twisted).
John
>I believe this can only be set globally:
>> import socket socket.setdefaulttimeout(seconds)
StefanUuuh this is no solution for me, because the website-checking
Stefantool is part of a very very big application running in an
Stefanapplication server, so globally setting the timeout may break a
Stefanlot of other things...
Can you try this patch: http://python.org/sf/723312
? It's against current CVS. Also, it doesn't include urllib or urllib2
changes, just httplib. Getting this completed would be nice.
Skip sk**@pobox.com writes:
>I believe this can only be set globally:
>>
>import socket
>socket.setdefaulttimeout(seconds)
StefanUuuh this is no solution for me, because the website-checking
Stefantool is part of a very very big application running in an
Stefanapplication server, so globally setting the timeout may break a
Stefanlot of other things...
Can you try this patch:
http://python.org/sf/723312
? It's against current CVS. Also, it doesn't include urllib or urllib2
changes, just httplib. Getting this completed would be nice.
Great. Added some comments, will try to write tests and urllib2 patch
later.
John
Stefan Palme wrote:
is there a way to modify the time a call of
urllib.open(...)
waits for an answer from the other side? Have a tool
I'm working on adding a socket_timeout parametero to urllib2.urlopen.
Regards,
--
.. Facundo
..
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jeff |
last post by:
Hiya
im trying to pull tags off a website using python ive got a few things
running that have the potential to work its just i cant get them to
becuase of certain errors?
basically i dont...
|
by: John Hunter |
last post by:
I have a test script below which I use to fetch urls into strings,
either over https or http. When over https, I use m2crypto.urllib and
when over http I use the standard urllib. Whenever, I...
|
by: Pieter Edelman |
last post by:
Hi all,
I'm trying to submit some data using a POST request to a HTTP server with
BASIC authentication with python, but I can't get it to work. Since it's
driving me completely nuts, so here's...
|
by: Timothy Wu |
last post by:
Hi,
I'm trying to fill the form on page
http://www.cbs.dtu.dk/services/TMHMM/ using urllib.
There are two peculiarities. First of all, I am filling in incorrect
key/value pairs in the...
|
by: Jaap Spies |
last post by:
Hi,
Running Fedora Core 4: Python 2.4.3 and Python 2.4.1.
I'm getting:
IOError: (2, 'No such file or directory')
all the time.
Trying to track down this problem:
Python 2.4.1 (#1, May 16...
| |
by: John Nagle |
last post by:
There's no way to set a timeout if you use "urllib" to open a URL.
"HTTP", which "urllib" uses, supports this, but the functionality
is lost at the "urllib" level.
It's not available via "class...
|
by: supercooper |
last post by:
I am downloading images using the script below. Sometimes it will go
for 10 mins, sometimes 2 hours before timing out with the following
error:
Traceback (most recent call last):
File...
|
by: John Nagle |
last post by:
I thought I had all the timeout problems with urllib worked around,
but no.
socket.setdefaulttimeout is useful, but not always effective.
I'm setting that to 15 seconds.
If the host end won't...
|
by: John Nagle |
last post by:
urllib has a "hole" in its timeout protection.
Using "socket.setdefaulttimeout" will make urllib time out if a
site doesn't open a TCP connection in the indicated time. But if the site
opens...
|
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,...
|
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...
| |
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,...
|
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: 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...
|
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,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |