I am trying to launch and then stop an Android emulator from a python 2.5 script (to be executed with monkeyrunner
), and I wrote the following code:
def launchDevice(avd_name, wipe=False):
cmd = ['~/android-sdk-linux/tools/emulator -avd %s' % avd_name]
if wipe:
cmd.append(' -wipe-data')
print 'Starting the emulator %s...' % avd_name
emulator = subprocess.Popen(cmd, shell=True, bufsize=-1)
return emulator
#end
def main():
# launch the emulator
emulator_proc = launchDevice('Nexus5')
print emulator_proc.pid
# stop the emulator
os.kill(emulator_proc.pid, signal.SIGTERM)
#end
if __name__ == '__main__':
main()
When I execute this script I get a working Android emulator (so the subprocess.Popen
instruction works), but then I get an error (TypeError: kill(): 1st arg can't be coerced to int
) in os.kill
function since the emulator_proc
's PID is None
(verified by the output message).
How is it possible to have a None
PID?