python - subprocess.Popen() launches two process instead of one -


i working on project using raspberry-pi , detect button push on pi launch program (squeezelite https://code.google.com/p/squeezelite/) , when button pushed again kill program using pid captured when program launched. think python subprocess module choice this, however, having problem can't resolve.

the code:

proc=subprocess.popen(['squeezelite','-o','sysdefault:card=alsa','-n','test','-m', '01:00:00:00:00:03','-z']) 

seems launch 2 processes:

2886 pts/0   z+    0:00 [squeezelite] defunct  2887 ?       slsl  0:00 squeezelite -o sysdefault:card=alsa -n test -m 01 00 00 00 00 03 -z 

and proc.pid returns pid of the first one.

if call proc.communicate() first process cleaned , left second one, way 1 want. however, left not knowing pid of second process (because proc.pid gives me first 1 gone). not able use pid in kill command.

i have tried various combinations of subprocess.popen different options (eg string argument, parameter argument, shell=true, shell=false) , each 1 gives similar result.

can assist me in getting work? or better way launch program , @ later time kill it?

thanks aussiew

you using squeezelite's -z option, daemonizes process. explains why additional process being created. think best solution use os daemonizing tools (eg. start-stop-daemon), simplifying calls python. there guide daemonizing squeezelite in debian squeeze, can started.

you need start process , save pid in file, can stop later. 1 approach might use daemon script takes 2 parameters: start/stop , identifier button.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -