在python中进行超过2级的多处理 [英] Multiprocessing in python with more then 2 levels

查看:75
本文介绍了在python中进行超过2级的多处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个程序,想要生成一个像这样的进程-> n进程-> n进程

I want to do a program and want make a the spawn like this process -> n process -> n process

第二级生成程序可以进行多处理吗?使用python 2.6的multiprocessinf模块

can the second level spawn process with multiprocessing ? using multiprocessinf module of python 2.6

thnx

推荐答案

@vilalian的回答是正确的,但简洁.当然,当您最初的问题不清楚时,很难提供更多信息.

@vilalian's answer is correct, but terse. Of course, it's hard to supply more information when your original question was vague.

稍微扩展一下,您可以让原始程序生成其n进程,但是它们与原始程序稍有不同,因为您希望它们生成(每个,如果我理解您的问题) n更多进程.您可以通过使它们运行与原始过程相似的代码来完成此任务,但是会产生新的程序集来执行手头的任务,而无需进一步处理,或者您可以使用相同的代码/入口点,只是提供不同的参数-类似

To expand a little, you'd have your original program spawn its n processes, but they'd be slightly different than the original in that you'd want them (each, if I understand your question) to spawn n more processes. You could accomplish this by either by having them run code similar to your original process, but that spawned new sets of programs that performed the task at hand, without further processing, or you could use the same code/entry point, just providing different arguments - something like

def main(level):
    if level == 0:
        do_work
    else:
        for i in range(n):
            spawn_process_that_runs_main(level-1)

并从level == 2

这篇关于在python中进行超过2级的多处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆