title: Timeout and high cpu load problems using multiple telnet connection threads in python
body: <p>I want to connect to multiple telnet hosts using threading in python, but I stumbled about an issue I'm not able to solve.</p>
  
  <p>Using the following code on MAC OS X Lion / Python 2.7</p>
  
  <pre><code>import threading,telnetlib,socket
  
  class ReaderThread(threading.Thread):
      def __init__(self, ip, port): 
          threading.Thread.__init__(self)
          self.ip = ip
          self.port = port
          self.telnet_con = telnetlib.Telnet()
  
      def run(self):
          try:
              print 'Start %s' % self.ip
              self.telnet_con.open(self.ip,self.port,30)
              print 'Done %s' % self.ip
          except socket.timeout:
              print 'Timeout in %s' % self.ip
  
      def join(self):
          self.telnet_con.close()
  
  ta = []
  
  t1 = ReaderThread('10.0.1.162',9999)
  ta.append(t1)
  t2 = ReaderThread('10.0.1.163',9999)
  ta.append(t2)
  
  for t in ta:
      t.start()
  print 'Threads started\n'
  </code></pre>
  
  <p>In general it works, but either one of the threads (it is not always the same one) takes a long time to connect (about 20 second and sometimes even runs into a timeout). During that awfully long connection time (in an all local network), cpu load also goes up to 100 %.</p>
  
  <p>Even more strange is the fact that if I'm using only one thread in the array it always works flawlessly. So it must have something to do with the use of multiple threads. </p>
  
  <p>I already added hostname entries for all IP addresses to avoid a DNS lookup issue. This didn't make a difference.</p>
  
  <p>Thanks in advance for your help.</p>
  
  <p>Best regards</p>
  
  <p>senexi</p>