3

I've ten different adb commands and want to execute it concurrently as a separate process . I've used subprocess module & but process doesn't seem to run concurrently. Is there an efficient method in python to run process concurrently? My code snippet is below

def run(com):
       sub = subprocess.Popen(command, shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)
    return sub.communicate()
cmd =[adb commands 1 to 10]
for i in cmd:
   run(i)
1

3 Answers 3

8

This worked for me :

import subprocess
subprocess.call("adb devices",shell=True)

Here in place of "adb devices" you can write any adb commands.

Sign up to request clarification or add additional context in comments.

1 Comment

While this code may answer the question, providing additional context regarding how and why it solves the problem would improve the answer's long-term value.
0

Just drop sub.communicate().

Popen.communicate(input=None) Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.

1 Comment

None of stuff listed in quoted docs would be performed, including waiting for process to terminate. So none of previous processes would block creating new.
0

Running ADB through python

Although it might seem complicated, its actually pretty easy. You can use:

  1. python-pure-adb.

Install it using pip install python-pure-adb. You can also take a look at the documentation, which will help you out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.