0
点赞
收藏
分享

微信扫一扫

python multiprocessing Pool 进程池内存上涨问题解决方法

Gascognya 2022-03-27 阅读 35
import os
import json
from multiprocessing import Pool
from contextlib import closing





def tick(filename, i_):
    try:
        print(i_)
        #s = get_one_note_list(filename)
        #s = get_one_note_list_s(s)
        #with open("D:/MIDI_json/a_{}.json".format(i_), "w", encoding="utf-8") as f:
            #json.dump({"data": s}, f)

    except Exception as e:
        pass
        # print("c{}".format(e),"D:/MIDI_json/a_{}.json".format(i_))



if __name__ == '__main__':
    # 只要这里你定义不同的scheduler就建立了多个调度器
    p = Pool(10)
    with closing(p) as P:

        list1 = []

        for i_, i in enumerate(midi_list[40896:60000]):
            i_ += 40896
            print(i_)

            res = p.apply_async(tick, [i, i_, ])

            list1.append(res)

        P.close()

        P.join()

        print('进程池创建的进程已结束')

        # for j in list1:
        #     print(j.get())

        P.close()

举报

相关推荐

0 条评论