You are not logged in.
Pages: 1
Hello.
I have a webpy app in which I want to execute cvlc from.
Currently the code I am using is this:
pid = subprocess.Popen(['/usr/bin/cvlc', 'pvr:///dev/video0', '--sout', '#rtp{dst=239.255.1.1,port=5004,mux=ts}'],stdout=subprocess.PIPE,stderr=subprocess.PIPE).pid
However, whenever I kill the process it stays defuncted until I kill the python script.
What can I do to prevent this from happening?
I am guessing I have to spawn the program into its own parent process.
Offline
Not sure if there is anything in python, but you could try executing it with the "setsid" command. That should launch that program in a news separate session from python
Offline
I've never noticed this behaviour in my apps you can try to use pid.poll to see if the subprocess has terminated, if it is reporting a return code but still be listed as a process try doing delete pid to see if it cleans it up.
Offline
Offline
I think your script needs a signal handler for SIGCHLD (see http://docs.python.org/library/signal.html).
Offline
Have you tried running the program by itself (not with python) using the same parameters? Does it close die properly?
Just wrote a quick little program to test this...
import subprocess
import time
subprc = subprocess.Popen("gnome-mplayer",stdout=subprocess.PIPE,stderr=subprocess.PIPE)
print "PID: {0}".format(subprc.pid)
while (subprc.poll() == None):
print(subprc.returncode)
time.sleep(1)
and it works fine, process dies when app closes.
So my best guess is that cvlc isn't closing properly
Offline
But see that is the problem... I can't wait for the app to close. I need the app to fork/spawn/whatever in the background so my webapp can continue to work (and not wait for the program to close). It seems like the best way to do this is with a bash helper script in which I use & to fork the program in the background.
Offline
subprocess does fork the application to the background, all my test code does is check to make sure the process is closing by itself.
why not try my little test code with cvlc and a short video and see if cvlc closes by itself, if it isn't thats your problem. All I'm saying is that
subprocess works the way you want it to, the problem lies elsewhere.
Offline
Not really...
import subprocess
import time
subprc = subprocess.Popen("gedit",stdout=subprocess.PIPE,stderr=subprocess.PIPE)
print "PID: {0}".format(subprc.pid)
time.sleep(60)
Now if you run killall gedit and ps aux in another terminal you'll see
pyther 17315 6.2 0.0 0 0 pts/4 Z+ 11:09 0:00 [gedit] <defunct>
before the script exits. In my case the script will never exit, because it is a webpy app so over a month or so, I'd have at least 30 zombie processes.
However, I ended up finding a hidden switch for vlc --daemon which works wonders.
Offline
Sorry, I should have caught that, poll cleans up the process for you.
I know you solved this by other means but another solution would be to have a garbage collection array something like this...
OldProcs = []
def CleanUp():
while i < len(OldProcs):
if (OldProcs[i].poll() != None):
OldProcs.pop(i)
else:
i++
Then just add a couple of lines to your code
global OldProcs
OldProcs.append(subprc)
CleanUp()
Not ideal but effective none the less
Offline
Not sure if there is anything in python, but you could try executing it with the "setsid" command. That should launch that program in a news separate session from python
This is what I do too, with an extra setsid (I found that works better) and signal.SIGCHLD left at the default:
Popen("setsid setsid "+cmd+" >/dev/null 2>&1 < /dev/null", shell=True)
Offline
I think this will help:
http://code.activestate.com/recipes/278731/
you can use the createDaemon function to spawn a new process. It just need a little editing.
(I used it once to start the xmms2 daemon, if it's any help: http://code.google.com/p/etude-music-pl … ain.py#379)
Offline
Pages: 1