Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:47:41+00:00 2026-06-14T14:47:41+00:00

Im trying to use monkeyrunner to configure multiple tablets attached to the same pc.

  • 0

Im trying to use monkeyrunner to configure multiple tablets attached to the same pc. The code works ok for 1 tablet but the moment I try to run it on multiple tablets it all blows up.

Here is the code which invokes the monkeyrunner python file. mr1.py is the monkeyrunner file I am trying to run.

import sys

import util
import threading
import commands
class myThread (threading.Thread):
    def __init__(self, threadID, deviceId,env_path):
        self.threadID = threadID
        self.deviceId = deviceId
        self.path = env_path
        threading.Thread.__init__(self)
    def run(self):
        print "Starting " + self.deviceId
        ret = commands.getstatusoutput(self.path+"monkeyrunner mr1.py "+self.deviceId)
        print ret
        print "Exiting " + self.deviceId

def main():
    connected_devices = util.get_connected_devices()
    count = 0
    path = "/Users/ad/Desktop/android-sdk-macosx/tools/"
    for device in connected_devices:
        thread = myThread(count,device[0],path)
        thread.start()
        count = count + 1


if __name__ == "__main__":
    main()

I came across this blogpost which describes about a race condition in monkeyrunner. I am not sure if thats what is causing the problem.

http://distributedreasoner.blogspot.com/2011/06/android-monkeyrunner-and-google-adb.html

I also tried using the MAML library mentioned in the above blog post, but I still havent been able to get monkeyrunner to execute simulatenously on multiple devices. Here is the actual monkeyrunner code.

import sys
import maml
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice



deviceId = sys.argv[1]

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection(10.0,deviceId)

packagename = "com.android.settings"
classname =    "com.android.settings.DisplaySettings" #SecuritySettings" #".DisplaySettings" 
componentname = packagename + "/" + classname 
device.startActivity(component=componentname) 
maml.click(device,1088,300)
MonkeyRunner.sleep(0.4)
maml.click(device,864,361)
MonkeyRunner.sleep(0.4)
maml.click(device,612,621)
MonkeyRunner.sleep(0.5)
device.press ('KEYCODE_HOME', 'DOWN_AND_UP')

print "Exiting for device !" + deviceId

Based on Commonsware’s question, I replaced the threading code with the following sequential code and it seems to work ok, but obviously this is not the most ideal situation.

for device in connected_devices:
        print device[0]
        ret = commands.getstatusoutput(path+"monkeyrunner mr1.py "+device[0])
        print ret

Because Android doesnt allow you to modify location / language settings etc programatically, and I need to configure many tablets to change settings, the immediate option was to use MonkeyRunner. A couple of notes, I am open to other tools that I could use other than monkeyrunner to solve this problem.
Any help on this problem would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:47:42+00:00Added an answer on June 14, 2026 at 2:47 pm

    What settings are you trying to change? language can be sort of done within your application if that is the only one.

    public void setLocale(Locale locale, Instrumentation inst){
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        inst.getTargetContext().getResources().updateConfiguration(config, inst.getTargetContext().getResources().getDisplayMetrics());
    }
    

    Are all your tablets api level 16+ (jely bean?) if so you might want to look at http://developer.android.com/tools/testing/testing_ui.html

    Finally if you still want to do it with monkey runner I would recommend getting hold of all your devices in one thread and then passing in each device to each thread separately.

    Python is not my specialty and i do not have access/knowledge fo all the libraries you are using (i could do it in java for you maybe?) but what i think might work better is something like:

    class myThread (threading.Thread):
        def __init__(self, device):
            self.device = device
            threading.Thread.__init__(self)
    
        def run(self):
            packagename = "com.android.settings"
            classname = "com.android.settings.DisplaySettings"
            componentname = packagename + "/" + classname
            self.device.startActivity(component=componentname)
            maml.click(self.device, 1088, 300)
            MonkeyRunner.sleep(0.4)
            maml.click(self.device, 864, 361)
            MonkeyRunner.sleep(0.4)
            maml.click(self.device, 612, 621)
            MonkeyRunner.sleep(0.5)
            self.device.press('KEYCODE_HOME', 'DOWN_AND_UP')
    
    
    def main():
        connected_devices = util.get_connected_devices()
        count = 0
        devices = []
        for deviceId in connected_devices:
            devices[count] = MonkeyRunner.waitForConnection(10.0, deviceId[0])
            count = count + 1
        for device in devices:
            thread = myThread(device)
            thread.start()
    
    
    if __name__ == "__main__":
        main()
    

    basically the difference is as i said above, you get all the devices in sequence and then call each thread with the device you got sequentially. Does that make sense?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying use a set of filter functions to run the appropriate routine,
I am trying use filehelpers class builder but I am kinda confused on what
I'm trying use Lift and CalendarMonthView widget to build a appointment system. CalendarMonthView works
Trying to use Net::SFTP, version 2.05 (appears to be the latest). But it fails
I was trying use svn to find a checkin using svn log, but it
I am trying use std::copy to copy from two different iterator. But during course
I'm trying use the Sum method in a lambda expression for a comparison, but
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I am trying use TinyMCE to get code syntax to be displayed in the
I am trying use cursor for pagination. Forwarding pagination work fine, but I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.