while True: if self.frame_queue.empty() != True: frame = self.frame_queue.get() #p.stdin.write(frame.tobytes()) p.stdin.write(frame) 发生av_interleaved_write_frame(): Broken pipe 中断如何自动恢复
时间: 2023-12-03 20:44:47 浏览: 34
发生 "av_interleaved_write_frame(): Broken pipe" 错误通常是由于管道已经关闭或者写入数据的进程已经退出导致的。解决这个问题的方法是重新打开管道并重新启动进程。
在你的代码中,你可以在 `p.stdin.write(frame)` 前加上一个 try-except 语句来捕获 Broken Pipe 错误。如果捕获到了这个错误,可以尝试重新启动进程并重新打开管道。
例如:
```python
while True:
if self.frame_queue.empty() != True:
frame = self.frame_queue.get()
try:
p.stdin.write(frame)
except IOError as e:
if e.errno == errno.EPIPE:
# Broken pipe error
print("Broken pipe, trying to restart process")
p.terminate()
p = subprocess.Popen("command to start process", stdin=subprocess.PIPE)
```
请注意,你需要在 except 语句中替换 "command to start process" 为实际启动进程的命令。