小编Ian*_*ica的帖子

Python多处理 - AssertionError:只能加入子进程

我正在进行python mutliprocessing模块的第一次尝试,我遇到了一些问题.我对线程模块非常熟悉,但我需要确保我正在执行的进程并行运行.

这是我正在尝试做的概述.请忽略未声明的变量/函数之类的内容,因为我无法完全粘贴代码.

import multiprocessing
import time

def wrap_func_to_run(host, args, output):
    output.append(do_something(host, args))
    return

def func_to_run(host, args):
    return do_something(host, args)

def do_work(server, client, server_args, client_args):
    server_output = func_to_run(server, server_args)
    client_output = func_to_run(client, client_args)
    #handle this output and return a result
    return result

def run_server_client(server, client, server_args, client_args, server_output, client_output):
    server_process = multiprocessing.Process(target=wrap_func_to_run, args=(server, server_args, server_output))
    server_process.start()  
    client_process = multiprocessing.Process(target=wrap_func_to_run, args=(client, client_args, client_output))
    client_process.start()
    server_process.join()
    client_process.join()
    #handle the output and return some result    

def run_in_parallel(server, client):
    #set up commands for first …
Run Code Online (Sandbox Code Playgroud)

python unix python-2.7 python-multiprocessing

8
推荐指数
1
解决办法
5734
查看次数

标签 统计

python ×1

python-2.7 ×1

python-multiprocessing ×1

unix ×1