title: Python, recreate a socket and automatically reconnect
body: <p>I'm writing a IRC bot in Python. </p>
  
  <p>Source: <a href="http://pastebin.com/gBrzMFmA" rel="noreferrer">http://pastebin.com/gBrzMFmA</a> ( sorry for pastebin, i don't know how to efficently/correctly use the code tagthing on here )</p>
  
  <p>When the "irc" socket dies, is there anyway I could go about detecting if its dead and then automatically reconnecting?</p>
  
  <p>I was googling for awhile now and found that I would have to create a new socket. I was trying and added stuff like catching socket.error in the while True: but it seems to just hang and not reconnect correctly..</p>
  
  <p>Thanks for help in advance</p>