title: What should I do if socket.setdefaulttimeout() is not working?
body: <p>I'm writing a script(multi-threaded) to retrieve contents from a website, and the site's not very stable so every now and then there's hanging http request which cannot even be time-outed by <code>socket.setdefaulttimeout()</code>. Since I have no control over that website, the only thing I can do is to improve my codes but I'm running out of ideas right now. </p>
  
  <p>Sample codes:</p>
  
  <pre><code>socket.setdefaulttimeout(150)
  
  MechBrowser = mechanize.Browser()
  Header = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 (.NET CLR 3.5.30729)'}
  Url = "http://example.com"
  Data = "Justatest=whatever&amp;letstry=doit"
  Request = urllib2.Request(Url, Data, Header)
  Response = MechBrowser.open(Request)
  Response.close()
  </code></pre>
  
  <p>What should I do to force the hanging request to quit? Actually I want to know why <code>socket.setdefaulttimeout(150)</code> is not working in the first place. Anybody can help me out?</p>
  
  <p><strong>Added:(and yes problem still not solved)</strong> </p>
  
  <p>OK, I've followed tomasz's suggestion and changed codes to <code>MechBrowser.open(Request, timeout = 60)</code>, but same thing happens. I still got hanging requests randomly till now, sometimes it's several hours and other times it could be several days. What do I do now? Is there a way to force these hanging requests to quit? </p>