我有一段代码,代码可以正常循环一次或两次,但最终会构建内存.我试图找到内存泄漏,memory_profiler这是结果:
row_nr    Memory_usage    Memory_diff    row_text
 470     52.699 MiB     0.000 MiB      ax.axis('off')
 471     167.504 MiB    114.805 MiB    fig.savefig('figname.png', dpi=600)
 472     167.504 MiB    0.000 MiB      fig.clf()
 473     109.711 MiB    -57.793 MiB    plt.close()
 474     109.711 MiB    0.000 MiB      gc.collect()`
Run Code Online (Sandbox Code Playgroud)
我创建了这样的图:
fig, ax = plt.subplots()
任何建议109 - 52 = 57 MiB去了吗?
我正在使用python 3.3.
我正在尝试使用一组计算机来运行数百万个小型模拟。为此,我尝试在主计算机上设置两台“服务器”,一台用于将队列中的输入变量添加到网络,另一台用于处理结果。
这是将内容放入模拟变量队列的代码:
"""This script reads start parameters and calls on run_sim to run the
simulations"""
import time
from multiprocessing import Process, freeze_support, Manager, Value, Queue, current_process
from multiprocessing.managers import BaseManager
class QueueManager(BaseManager):
    pass
class MultiComputers(Process):
    def __init__(self, sim_name, queue):
        self.sim_name = sim_name
        self.queue = queue
        super(MultiComputers, self).__init__()
    def get_sim_obj(self, offset, db):
        """returns a list of lists from a database query"""
    def handle_queue(self):
        self.sim_nr = 0
        sims = self.get_sim_obj()
        self.total = len(sims)
        while len(sims) > 0:
            if self.queue.qsize() > 100:
                self.queue.put(sims[0]) …Run Code Online (Sandbox Code Playgroud)