urllib.urlopen() freezes unexpectedly

  • Thread starter Christodoulos Fragoudakis
  • Start date
C

Christodoulos Fragoudakis

Hello everyone! Can someone help us with the following problem:

We are performing an urllib.urlopen() in order to fetch a text file from
a https server. Most of the time the function works as expected but
every now and then it freezes because of an unexpected error. We do know
that the problem is not a network error because the code is inside a
try-except block and we don't get an exception. The program just freezes
waiting for ever for the execution of the urllib.urlopen() line to stop.
The relevant code fragment is the following:

try:
file_h = urllib.urlopen("https://<urlpath>/test.txt")
except:
print "Network Error"

The server we are connecting to is creating a text file every 30 minutes
which may be empty and immediately replaces the previous one. When the
freezing situation occurs we found out that even a browser connection to
the above url hangs also, waiting forever to display the file.

How can we time the operation and stop it after a specified time
interval? Do threads help and how?

Any help will be greatly appreciated.
 
C

Christos TZOTZIOY Georgiou

[replied in Greek, repeating here in English]
Hello everyone! Can someone help us with the following problem:

[snip: urllib.urlopen occasionally freezes; it doesn't seem to be
Python-specific, since a browser also freezes now and then for the same
url]
How can we time the operation and stop it after a specified time
interval? Do threads help and how?

The urllib module uses the builtin socket module; the
socket.setdefaulttimeout function will allow you to make the connection
abort after a timeout.

Please let us know if that worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top