python并行编程
嗨,我需要一些指导,如何编写执行其他Python程序的程序,但最多一次例如6次,并且始终尝试运行6个进程,即使一个进程最终结束,
我也想知道这些进程发生了什么?知道,但我不想等待任何进程完成
刚刚创建的进程的 pid 是什么?它还在运行吗?或者出现错误?或者它成功完成?
一些工作经理...
import subprocess
def start():
proc = {}
for i in range (0,6):
proc[i] = subprocess.Popen(
['python', 'someprogramm.py', '--env', 'DEVELOPMENT', '-l'],
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT
)
if __name__ == '__main__':
start()
hi i need some guidelines how to write programm that executes other python programm but in maximum for example 6 times at once and always try to be 6 process be running even if one ends up
also i would like to know what is happening to those processes right know but i dont want to wait to any process to finish
what is the pid of just created process? and its still running? or there has been an error? or it finish sucessfully?
some job manager ...
import subprocess
def start():
proc = {}
for i in range (0,6):
proc[i] = subprocess.Popen(
['python', 'someprogramm.py', '--env', 'DEVELOPMENT', '-l'],
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT
)
if __name__ == '__main__':
start()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 celery。
Use celery.
看看 supervisord。听起来它会做你想做的事。
Have a look at supervisord. It sounds like it will do what you want.
也许您可以尝试使用多处理模块,它可以处理 工作进程池看起来与您尝试实现的目标类似。
Maybe you can try with the multiprocessing module, it can handles pool of worker processes that seems similar to what you try to achieve.
您可以使用
poll()
检查进程是否仍在运行的方法。您必须循环遍历每个进程并检查它是否运行,否则运行一个新进程。You can use the
poll()
method to check if a process is still running. You'd have to loop through each process and check if it runs, and otherwise, run a new process.