0
我使用的第一個回答這個問題可用內存多處理
Overcoming Python's limitations regarding instance methods
醃製方法,能夠使用多進程模塊上我自己的一個類的方法。
舉個例子,讓我們說,我有以下幾點:
from multiprocessing import Pool
def myParallelFunc(my_list, a, b, inst):
# do something
return True
def myFunc:
# instantiate custom class
my_instance = MyObject()
pool = Pool()
pool.map(functools.partial(myParallelFunc, a=5, b=7, inst=my_instance), my_list)
# SOLUTION!!!
pool.close()
現在我有另一個程序調用myFunc的假設100倍。 每次我打電話給myFunc時,一些內存都被佔用,永遠不會釋放。 有沒有辦法明確釋放它?
你怎麼知道它是永遠不會被釋放? Python內存管理應該爲你處理事情。 – Pierce 2012-04-02 11:15:16
我使用「top」進行監控,並且只在最後發佈,當程序退出時 – 2012-04-02 11:22:29