如何知道特定进程在python中运行?

时间:2017-04-10 09:10:52

标签: python process subprocess

从网络摄像头接收到警报后,我执行一个命令,查看每个有活动警报的摄像机的实时视频流15秒。 我的代码很简单:

if alarms:
#this is working and the cameras are displayed for 15 seconds
p=subprocess.Popen(["cvlc","rtsp://IP_ALARM:554","--run-time=15","--stop-time=15","vlc://quit"])

我只是想知道如何防止多次显示同一个相机。

如果我有来自同一相机的两个闹钟,则此相机将显示两次。在警报中,我有每个摄像头的索引。 谢谢。

1 个答案:

答案 0 :(得分:0)

为什么不向命令添加参数?

alarms = [{'ip': '192.168.0.1', 'offline': True}]
for alarm in alarms:
    if alarm['offline']:
        #this is working and the cameras are displayed for 15 seconds
        p=subprocess.Popen(["cvlc","rtsp://%s:554","--run-time=15","--stop-time=15","vlc://quit"] % alarm['ip'])