如何解决Python multiprocessing Pool进程池内存持续上涨的问题?

2026-05-26 16:001阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计220个文字,预计阅读时间需要1分钟。

如何解决Python multiprocessing Pool进程池内存持续上涨的问题?

pythonimport osimport jsonfrom multiprocessing import Poolfrom contextlib import closing

def tick(filename, i_): try: print(i_) except Exception as e: with closing(open(filename, 'a')) as f: f.write(str(e) + '\n')


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()


如何解决Python multiprocessing Pool进程池内存持续上涨的问题?


本文共计220个文字,预计阅读时间需要1分钟。

如何解决Python multiprocessing Pool进程池内存持续上涨的问题?

pythonimport osimport jsonfrom multiprocessing import Poolfrom contextlib import closing

def tick(filename, i_): try: print(i_) except Exception as e: with closing(open(filename, 'a')) as f: f.write(str(e) + '\n')


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()


如何解决Python multiprocessing Pool进程池内存持续上涨的问题?