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)
MRSK
  • 63
  • 1
  • 1
  • 8
  • I guess this can be useful http://stackoverflow.com/questions/18864859/python-executing-multiple-functions-simultaneously – Andersson Jun 22 '15 at 08:05

3 Answers3

7

This worked for me :

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

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

Vivek Gupta
  • 353
  • 4
  • 13
  • 4
    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. – Alexander Mar 18 '18 at 13:19
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.

Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
  • 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. – Łukasz Rogalski Jun 22 '15 at 07:58
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.