I have a python cgi/html that takes url and launches on epiphany-browser. However, after the media/video is over, I need the browser to terminate. On other posts, it seems there are ways to do this with vlc-media and other players. But I haven't found one with a browser.
Basic framework around the command looks like:
msg = form.getvalue("msg", "(no msg)")
.......
## in-progress of msg = "sudo -u vnc " + msg + " "
.......
from subprocess import *
print Popen(msg, shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]
How do I implement such that the command (url) that gets executed shuts down after the streaming(youtube,cnn, etc) has been finished?
Thanks.
The simplest way to do this would be to use pkill
. As you're looking to kill an instance of epiphany
, a browser in the Unix family of operating systems, you'd use something like:
import os
os.system("pkill epiphany-browser")
If you executable is named something other than epiphany-browser
change the second part of the pkill
command to match.
Also bear in mind this will kill all processes with that name. To only kill the newest you can do something like:
import os
os.system("pkill -n epiphany-browser")
If you want to be really clever, you can try to graph the actual process number after you launch it:
import os
# launch stuff...
epiphanyPID=os.system("pgrep -n epiphany-browser")[2]
# do other stuff...
os.system("kill -9 " + epiphanyPID)
Also you should probably use the webbrowser
object rather than opening with Popen
. It lacks a close
as far as I understand from the documentation, but for opening sessions it's the preferred solution. Epiphany
is supported via the Galeon
object:
20.1. webbrowser — Convenient Web-browser controller