python启动另外一个pc的进程_Python终止一个子进程(启动另一个进程)并重新启动它...

我正在尝试创建一个python脚本来启动程序livestreamer(启动程序mplayer),10秒后它应该会终止程序或子进程。这是我当前的代码,我想我知道原因,但我不知道如何解决它。

我认为问题是子进程启动livestreamer,然后程序livestreamer启动程序mplayer。Python不知道mplayer,也不能关闭它。我怎样才能在10秒后杀死livestreamer和mplayer,然后重新启动它们作为一个循环?

我使用的是Ubuntu14.04(Linux)和Python2.7.6import subprocess

import time

import os

import sys

import signal

url = "http://new.livestream.com/accounts/398160/events/3155348"

home = os.environ['HOME']

if not os.geteuid() == 0:

if not os.path.exists('/%s/.config/livestreamer' % home):

os.makedirs('/%s/.config/livestreamer' % home)

lscfg = open('%s/.config/livestreamer/config' % home, 'w+')

lscfg.write("player=mplayer -geometry 0%:0% -nomouseinput -loop 100 -noborder -fixed-vo")

lscfg.close()

cmd = "livestreamer %s best --player-continuous-http --player-no-close" % url

while True:

proc1 = subprocess.Popen(cmd.split(), shell=False)

time.sleep(10)

proc1.kill()

解决方案:

^{pr2}$

如你所见操作系统(“killall-9mplayer”)是终止进程mplayer的命令。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值