如何有效地管理这些子流程?
我有一个可以下载然后转换视频的脚本。我试图一次完成所有下载(很多 wget),然后在完成后进行转换。现在我必须等待每个文件单独下载,然后在完成后进行转换。我希望所有下载请求同时运行。
这是我的“下载”脚本中阻止一切的部分。
for id in ids:
subprocess.Popen(cmd, shell=True).wait()
我的“转换”脚本正在等待下载脚本完成。 (这是必要的,因为我正在使用一组下载来组织所有内容。)
我可以使用队列,但这已经让这变得足够大了,我希望有一个更简单的解决方案。
谢谢
I've got a script that downloads and then converts videos. I'm trying to do all of the downloads at once(a lot of wgets) and then when they're done, convert them. Right now I have to wait while each file downloads individually and then convert when done. I want all the download requests to run concurrently.
Here's the part in my 'download' script that is holding everything up.
for id in ids:
subprocess.Popen(cmd, shell=True).wait()
I have my 'convert' script waiting on the download script to finish. (which is necessary, because i'm using sets of downloads to organize everything.)
I could use a queue but this I've already made this a big enough mess and I'm hoping there is a simpler solution.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以
这样使用,您将在同时作业结束时等待。
you could use
as such you will wait just at the end of simultaneous jobs.
如果您的平台可用,您可以使用 xargs 作为简单的解决方案。
从手册页来看:
当然有更好的解决方案,但如果您需要一个快速的解决方案,这可能是最容易实现的。
You could use
xargs
as a simple solution, if that is availabe for your platform.From the man page:
There are certainly better solutions, but if you need a quick one this is probably the easiest to implement.