简体   繁体   English

Python脚本充满了内存

[英]Python script fills memory

I'm working on a script that consumes memory cumulatively and I don't know how to solve this. 我正在处理一个脚本,该脚本会累计消耗内存,但我不知道该如何解决。 Any help or suggestions are appreciated. 任何帮助或建议,表示赞赏。

Python garbage collector is failing somehow, what is going on? Python垃圾收集器以某种方式失败,这是怎么回事?

The code sample is below, some notes are following. 下面是代码示例,下面是一些注释。
I suspect the culprit is psspy but I don't have access to its code, is there a workaround somehow? 我怀疑罪魁祸首是psspy但我无法访问其代码,是否有某种解决方法?

ierr are all integers. ierr都是整数。
variable1 , etc are lists containing a single list of numbers (integers, reals or complexes). variable1等是包含单个数字列表(整数,实数或复数)的列表。

import psspy
psspy.psseinit(1200)

cases = []
... #Construction of a list of strings containing filenames like 'case010.sav'
faults = []
... #Construction of another list that doesn't contribute to the problem.

for filename in cases:
    psspy.case(filename) #It opens a 'case' that alters the output of the following functions
    ierr, variable1 = psspy.function1(parameters)
    ierr, variable2 = psspy.function2(parameters)
    ...
    ierr, variablen = psspy.functionn(parameters)
    ...
    for fault in faults:
        psspy.close_powerflow() #Documentation says it  
             #'Removes the current powerflow working case from PSS®E’s working memory.'
        psspy.case(filename)
        ...
        ierr, variable1 = psspy.function1(parameters)
        ierr, variable2 = psspy.function2(parametersl)
        ...
        ierr, variablen = psspy.functionn(parameters)
        ...

It could indeed be that there is some sort of leak in the psspy namespace. 的确可能是psspy名称空间中存在某种泄漏。 In order to understand more fully where the memory is being used you should use one of the Python profilers . 为了更全面地了解内存的使用位置,您应该使用Python分析器之一

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

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