python - Not able to give inputs to subprocess(process which runs adb shell command) after 100 iterations -


i want run stress test adb(android debug bridge) shell. ( adb shell in respect command line tool provided android phones).

i create sub-process python , in subprocess execute 'adb shell' command. there commands has given subprocess providing via stdin proper of sub process.

everything seems fine when running stress test. after around 100 iterations command give stdin not reach subprocess. if run commands in separate terminal running fine. problem stdin.

can tell me doing wrong. below code sample

class adb(): def __init__(self):     self.proc = subprocess.popen('adb shell', stdin=subprocess.pipe, stdout=subprocess.pipe, stderr=subprocess.stdout, shell=true,bufsize=0)   def provideamcommand(self, testparam):     try:         cmd1 = "am startservice -n com.test.myapp/.adbsupport -e \"" + "command" + "\" \"" + "test" + "\""           cmd2 = " -e \"" + "param" + "\"" + " " + testparam         print cmd1+cmd2         sys.stdout.flush()         self.proc.stdin.write(cmd1 + cmd2 + "\n")     except:         raise exception("phone not connected desktop or adb not available \n") 

if works first few commands blocks later might forgot read self.proc.stdout might lead (as docs warn) os pipe buffer filling , blocking child process.

to discard output, redirect os.devnull:

import os subprocess import popen, pipe, stdout  devnull = open(os.devnull, 'wb') # ... self.proc = popen(['adb', 'shell'], stdin=pipe, stdout=devnull, stderr=stdout) # ... self.proc.stdin.write(cmd1 + cmd2 + "\n") self.proc.stdin.flush() 

there pexpect module might better tool dialog-based interaction (if want both read/write intermitently).


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -