简体   繁体   English

Python多处理-进程重启后清除RAM

[英]Python Multiprocessing - clear RAM after process restart

I am using the python multiprocessing libary to handle big datasets in realtime. 我正在使用python多处理库来实时处理大型数据集。

Sometimes I need to restart the processes for changing some settings. 有时我需要重新启动更改某些设置的过程。

Is there a possibility to clear the data, which are saved in the RAM. 是否有可能清除保存在RAM中的数据。 I saw my RAM usage is growing ~2% / restart. 我看到我的RAM使用量正在增加〜2%/重新启动。

Please find following my code example: 请找到以下我的代码示例:

# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import multiprocessing
import sys

def calc(q):
    x=5
    for i in range (10):
        x = x+1
        q.put(x)

def calc_calc(quee, qq):
    for u in range (10):
        y = quee.get()
        z = y*10    
        qq.put(z)

def calc_end(queee, qqq):
    for w in range (10):
        h = queee.get()
        xy = h*10
        print(xy)
        qqq.put(xy)

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.button = QtGui.QPushButton('Test', self)
        self.button.clicked.connect(self.handleButton)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.button)

    def handleButton(self):   
        p1 = multiprocessing.Process(target=calc, args=(q,))
        #q = q.put(x)
        p2 = multiprocessing.Process(target=calc_calc, args =(q, qq,))
        #qq = qq.put(z)
        p3 = multiprocessing.Process(target= calc_end, args =(qq, qqq,))

        p1.start()
        p2.start()
        p3.start()    

        p1.join()
        p2.join()
        p3.join()    

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Window()

    #multiprocessing queue 1
    q = multiprocessing.Queue()
    #multiprocessing queue 3
    qq = multiprocessing.Queue()
    #multiprocessing queue 3 (aktuell nicht belegt)
    qqq = multiprocessing.Queue()

    window.show()
    sys.exit(app.exec_())

You can't explicitly free memory. 您不能显式释放内存。 What you can do is call Garbage Collector with gc.collect() according to Python Documentation . 您可以根据Python文档的 gc.collect()调用垃圾收集器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM