Python 在线程内使用计时器防止挂起代码

Python 在线程内使用计时器防止挂起代码,python,multithreading,timer,Python,Multithreading,Timer,我的程序创建一组线程,每个线程连接到一个网站以检索一些数据(使用mechanize浏览器)。 有时候,当我读取数据时,互联网会断开,然后程序会无限期挂起: response = br.open(url,timeout=30.0) headers = response.info() html = response.read() #the code hangs here 我一直在网上阅读有关signal.alarm的文章,但不建议在线程中使用。 我的问题是:我还可以用什么其他方法来处理这个问题?也

我的程序创建一组线程,每个线程连接到一个网站以检索一些数据(使用mechanize浏览器)。 有时候,当我读取数据时,互联网会断开,然后程序会无限期挂起:

response = br.open(url,timeout=30.0)
headers = response.info()
html = response.read() #the code hangs here
我一直在网上阅读有关signal.alarm的文章,但不建议在线程中使用。 我的问题是:我还可以用什么其他方法来处理这个问题?也许是计时器

提前谢谢