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

2 Answers2

5

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
  • 303
  • 4
  • 12
  • 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
  • 20,566
  • 8
  • 54
  • 89
  • 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