Search code examples
androidmultithreadingadbmonkeyrunner

monkeyrunner hangs when making a connection to the device


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.

here's the code

import threading

import datetime import os, sys

import ConfigParser from com.android.monkeyrunner

import MonkeyRunner, MonkeyDevice,MonkeyImage from datetime

import datetime import hashlib from java.net

import SocketException from com.ziclix.python.sql

import zxJDBC

def UseThread(data1, data2, data3, devID, Code, ScreenshotRef, logFile):

 device = MonkeyRunner.waitForConnection(10, devID)

'threaded code'

'initialization'

file = open(os.path.dirname(os.path.realpath(file)) + '\Samples.txt','r') while 1:

while 1: line = file.readline()

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()

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

device = MonkeyRunner.waitForConnection(10, devID)

the message says "Monkey command wake".

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.

Is there an issue making a connection when you have already made one? do I need to close the previous connection first?


Solution

  • MonkeyRunner waitForConnection works only for one device. You cannot run this twice. You can run from another instance