Python并行画图
作者Lou Xiao创建时间2020-04-20 17:24:00更新时间2020-04-20 18:26:00
要点: 如何释放内存
1.双击鼠标左键复制此行;2.单击复制所有代码。
1
def draw_image(job):
2
# 服务段画图,如果没有安装Desktop环境
3
import matplotlib
4
matplotlib.use('AGG')
5
import matplotlib.pylot as plt
6
# ....
7
plt.cla()
8
plt.clf()
9
# ...
10
# 释放内存 release matplotlib memory
11
plt.cla()
12
plt.clf()
13
plt.close('all')
14
15
def work(job):
16
try:
17
draw_image(job)
18
# 释放内存 collect garbage
19
gc.collect(0)
20
gc.collect(1)
21
gc.collect(2)
22
except Exception as e:
23
print("[ Err ]work for %s | Err: %s" % (a, e))
24
25
if __name__ == '__main__':
26
pool = multiprocessing.Pool(24)
27
for job in jobs:
28
pool.apply_async(work, args=(job,))
29
pool.close()
30
pool.join()
文章目录