您的位置:首页 > 编程语言 > Python开发

关于python subprocess的popen

2016-03-09 13:17 465 查看
一段代码,备忘

import subprocess

import os

import threading

def on_exit():

print("process is dead")

def monitor(process1,onexit):

print("process id %s waiting"% (process1.pid))

process1.wait()

onexit()

command=['mplayer']+["/home/aphero/1.mp4"]

process = subprocess.Popen(command,stdout=subprocess.PIPE, preexec_fn=os.setsid)

process_monitor = threading.Thread(target=monitor, args=(process, on_exit))

process_monitor.start()

print("test poll")

ret=process.poll()

while ret is None:

returncode=process.stdout.read(512)#实时读取返回数据

print(returncode)

ret=process.poll()

print("end")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: