urllib.urlopen() freezes unexpectedly

Christodoulos Fragoudakis chfrag at central.ntua.gr
Mon Jun 7 11:37:43 CEST 2004


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.



More information about the Python-list mailing list