python并行编程

发布于 2024-11-04 21:48:46 字数 539 浏览 0 评论 0原文

嗨,我需要一些指导,如何编写执行其他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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

临走之时 2024-11-11 21:48:46

看看 supervisord。听起来它会做你想做的事。

Have a look at supervisord. It sounds like it will do what you want.

何以心动 2024-11-11 21:48:46

也许您可以尝试使用多处理模块,它可以处理 工作进程池看起来与您尝试实现的目标类似。

Maybe you can try with the multiprocessing module, it can handles pool of worker processes that seems similar to what you try to achieve.

甩你一脸翔 2024-11-11 21:48:46

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文