Python Can';在subprocess.wait期间,无法写入
我正在使用omxplayer编写一个音乐播放器系统,一切都已完成,但我有一个问题,我需要检测子进程何时完成音乐。等待()直到进程结束,我必须向进程写入字节,例如“p”。encode()暂停,“q”。encode()停止等。。。 问题是我无法在等待子进程时将字节写入子进程。。。如果有人知道如何检测流程的结束并同时向其写入内容,欢迎您 这是我的密码:Python Can';在subprocess.wait期间,无法写入,python,subprocess,byte,stdin,wait,Python,Subprocess,Byte,Stdin,Wait,我正在使用omxplayer编写一个音乐播放器系统,一切都已完成,但我有一个问题,我需要检测子进程何时完成音乐。等待()直到进程结束,我必须向进程写入字节,例如“p”。encode()暂停,“q”。encode()停止等。。。 问题是我无法在等待子进程时将字节写入子进程。。。如果有人知道如何检测流程的结束并同时向其写入内容,欢迎您 这是我的密码: class MusicPlayer(Thread): def __init__(self, manager, playlist=[]):
class MusicPlayer(Thread):
def __init__(self, manager, playlist=[]):
self.playlist = []
self.index = 0
self.process = None
self.paused = False
self.stopped = False
self.manager = manager
self.progress_bar = MusicProgressBar(self)
self.progress_bar.start()
Thread.__init__(self)
def run(self):
while True:
if len(self.playlist) is 0:
time.sleep(1)
continue
self.process = subprocess.Popen(['omxplayer' , '-o' , 'local', self.playlist[self.index].file_url])
self.progress_bar.play(self.playlist[0].file_url)
self.paused = False
self.process.wait()
self.index += 1
if self.index >= len(self.playlist):
self.index = 0
def play(self, playlist):
self.playlist = playlist
self.index = 0
def next(self):
if self.process is None: return
self.process.stdin.write('q'.encode())
self.process.stdin.flush()
def before(self):
for i in range(0,2):
self.index -= 1
if self.index < 0:
self.index = len(self.playlist-1)
def stop(self):
if self.process is None: return
self.process.stdin.write('q'.encode())
self.process.stdin.flush()
self.stopped = True
def pause(self):
if self.process is None: return
if self.paused: return
self.process.stdin.write('p'.encode())
self.process.stdin.flush()
self.paused = True
def resume(self):
if self.process is None: return
if not self.paused: return
self.process.stdin.write('p'.encode())
self.process.stdin.flush()
self.paused = False
class MusicPlayer(线程):
def uuu init(self,manager,playlist=[]):
self.playlist=[]
self.index=0
self.process=None
self.paused=False
self.stopped=False
self.manager=经理
self.progress\u bar=音乐进度条(self)
self.progress\u bar.start()
线程。\uuuu初始化\uuuuu(自)
def运行(自):
尽管如此:
如果len(self.playlist)为0:
时间。睡眠(1)
持续
self.process=subprocess.Popen(['omxplayer','-o',local',self.playlist[self.index].file\u url])
self.progress\u bar.play(self.playlist[0]。文件\u url)
self.paused=False
self.process.wait()
自索引+=1
如果self.index>=len(self.playlist):
self.index=0
def播放(自我,播放列表):
self.playlist=播放列表
self.index=0
def next(自我):
如果self.process为None:返回
self.process.stdin.write('q'.encode())
self.process.stdin.flush()文件
def之前(自我):
对于范围(0,2)内的i:
self.index-=1
如果自指数<0:
self.index=len(self.playlist-1)
def停止(自):
如果self.process为None:返回
self.process.stdin.write('q'.encode())
self.process.stdin.flush()文件
self.stopped=True
def暂停(自我):
如果self.process为None:返回
如果self.pause:返回
self.process.stdin.write('p'.encode())
self.process.stdin.flush()文件
self.paused=True
def恢复(自我):
如果self.process为None:返回
如果没有自我暂停:返回
self.process.stdin.write('p'.encode())
self.process.stdin.flush()文件
self.paused=False
非常感谢你的回答!
向你问好,朱利安我想你可以改变这句话
self.process.wait()
转一圈
while self.process.poll() not None:
c = stdscr.getch()
if c != -1:
# check p, q
也就是说,继续轮询omxplayer进程是否完成。如果没有,请检查是否有按键。我想您可以更改这一行
self.process.wait()
转一圈
while self.process.poll() not None:
c = stdscr.getch()
if c != -1:
# check p, q
也就是说,继续轮询omxplayer进程是否完成。如果没有,请检查是否有按键。查看。查看。