title: monkeyrunner hangs when making a connection to the device
body: <p>Here's what I need to do. I have 2 devices which I need to test using monkeyrunner. It is an automated test using python and monkeyrunner. I want to execute the test simultaneously for the 2 devices so I thought of using thread.</p>
  
  <p>here's the code</p>
  
  <blockquote>
    <p>import threading</p>
    
    <p>import datetime import os, sys </p>
    
    <p>import ConfigParser from com.android.monkeyrunner </p>
    
    <p>import MonkeyRunner, MonkeyDevice,MonkeyImage from datetime </p>
    
    <p>import datetime import hashlib from java.net</p>
    
    <p>import SocketException from com.ziclix.python.sql </p>
    
    <p>import zxJDBC</p>
    
    <p>def UseThread(data1, data2, data3, devID, Code, ScreenshotRef,
    logFile):</p>
  
  <pre><code> device = MonkeyRunner.waitForConnection(10, devID)
  
  'threaded code'
  
  'initialization'
  </code></pre>
    
    <p>file = open(os.path.dirname(os.path.realpath(<strong>file</strong>)) +
    '\Samples.txt','r') while 1:</p>
    
    <p>while 1:
        line = file.readline()</p>
  
  <pre><code>if not line:
  
      print 'Done!'
  
      break
  
  else:
  
      line
  
  
  val=line.split('\t')
  
  data1 = val[0]
  
  data2 = val[1]
  
  data3 = val[2]
  
  threads = []
  
  for Code in cp.options('p'):
  
      devID = cp.get('product',Code).strip()
  
      ScreenshotRef = cp.get('source','ScreenshotRef') + '\\' + prodCode.upper()
  
      logFile = outputFolder + '\\' + prodCode.upper() + '\\logs.txt' 
  
      t=threading.Thread(target=UseThread,args=(data1, data2, data3, devID, prodCode, ScreenshotRef, logFile))
      threads.append(t)
      t.start()
  
  for i in range(0,len(threads)):
      threads[i].join()
  </code></pre>
  </blockquote>
  
  <p>The problem is this. When the while loops finish one run and proceed to 2nd run, the code hangs in the part when monkeyrunner is waiting for connection. To be exact, this is the part where it stops</p>
  
  <blockquote>
    <p>device = MonkeyRunner.waitForConnection(10, devID)</p>
  </blockquote>
  
  <p>the message says "Monkey command wake".</p>
  
  <p>I assume that the problem has something to do with the connection, not with the thread because I tried to print something before that line which makes a connection and it works. </p>
  
  <p>Is there an issue making a connection when you have already made one? do I need to close the previous connection first? </p>