在编译脚本中运行subprocess.popen具有很大的延迟
编辑:在此特定示例中,在Windows 10上使用Python 3.8。
我需要通过subprocess.popen运行ffprobe,以便我可以捕获和解析输出。如果我在脚本中执行此操作,它几乎可以立即运行,但是如果我用Pyinstaller编译脚本并做同样的事情,则需要超过0.8秒的时间才能完成。是否可以从编译脚本中更快地执行该技巧或任何方法?如果存在,我愿意听到特定于FFProbe的答案。
这就是我目前正在使用的。额外的代码是为了确保FFProbe在运行时不会闪烁控制台窗口(卸下控制台窗口实际上使其平均更快0.1秒)。
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(f'ffprobe -show_format -show_streams -of json "{file}"', startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
Edit: In this specific example, Python 3.8 is being used on Windows 10.
I need to run FFprobe through subprocess.Popen so I can capture and parse the output. If I do this in a script, it runs almost instantly, but if I compile my script with PyInstaller and do the same thing, it takes over 0.8 seconds to complete. Is there a trick or any way I can execute it faster from the compiled script? I'm willing to hear FFprobe-specific answers if they exist.
This is what I'm using currently. The extra code is for ensuring FFprobe doesn't flash a console window while running (removing the console window actually made it 0.1 seconds faster on average).
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(f'ffprobe -show_format -show_streams -of json "{file}"', startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论