相关疑难解决方法(0)

Python多处理导致许多僵尸进程

我一直在使用工作池来实现python的多处理库.我实现了以下代码

import main1
t1 = time.time()
p = Pool(cores) 
result = p.map(main1, client_list[client])
if result == []:
    return []
p.close()
p.join()
print "Time taken in performing request:: ", time.time()-t1
return shorted(result)
Run Code Online (Sandbox Code Playgroud)

但是,在运行该过程一段时间后,我得到了很多运行我的应用程序的后台进程.这是为我的应用程序做ps aux之后的快照

显示所有僵尸进程的快照

现在,我已经在stackoverflow上阅读了很多类似的问题,比如如何杀死多处理模块创建的僵尸进程?它要求使用我已经实现的.join(),并且我从这里学习了如何从Python Multiprocessing Kill Processes中杀死所有这些进程.但我想知道我的代码可能出错的地方.我无法在main1函数中共享所有代码,但是我已将整个代码块放在try catch块中,以避免主代码中的错误导致僵尸进程的情况.

def main1((param1, param2, param3)):
    try:
       resout.append(some_data) //resout in case of no error
    except:
        print traceback.format_exc()
        resout = []  //sending empty resout in case of error
    return resout
Run Code Online (Sandbox Code Playgroud)

我对并行编程和调试问题的概念还很陌生,结果很棘手.非常感谢任何帮助.

python multiprocessing

10
推荐指数
1
解决办法
5849
查看次数

Python多处理程序杀死进程

我正在学习如何使用Python多处理库.但是,当我浏览一些示例时,我最终在后台运行了许多python进程.

其中一个示例如下所示:

from multiprocessing import Process, Lock

def f(l, i):
    l.acquire()
    print 'hello world', i
    l.release()

if __name__ == '__main__':
    lock = Lock()

    for num in range(10):   # I changed the number of iterations from 10 to 1000...
        Process(target=f, args=(lock, num)).start()
Run Code Online (Sandbox Code Playgroud)

现在这是我的'TOP'命令的屏幕截图:

88950  Python       0.0  00:00.00 1    0    9     91    1584K  5856K  2320K  1720K  2383M  82441 1     sleeping 1755113321 799
88949  Python       0.0  00:00.00 1    0    9     91    1584K  5856K  2320K  1720K  2383M  82441 1     sleeping 1755113321 798 …
Run Code Online (Sandbox Code Playgroud)

python macos multiprocessing

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

multiprocessing ×2

python ×2

macos ×1