简体   繁体   English

程序退出后消耗的内存

[英]ram memory consumed after program exit

I am running a python script on linux terminal. 我在linux终端上运行python脚本。 The script has an infinite calculus loop and it never ends, so for now I'm stopping it with ctrl+C. 该脚本有一个无限的演算循环,它永远不会结束,所以现在我用ctrl + C停止它。 After that, all the ram memory consumed by the program (which is a lot, and I don't find the leakage yet) is still consumed, until the moment I close the terminal. 之后,该程序消耗的所有ram内存(很多,我还没有发现泄漏)仍被消耗,直到关闭终端为止。 What can be happening? 会发生什么事?

I would suggest using a combination of: How do I capture SIGINT in Python? 我建议使用以下组合: 如何在Python中捕获SIGINT? and How can I explicitly free memory in Python? 以及如何在Python中显式释放内存?

#!/usr/bin/env python
import signal
import sys
import gc
def signal_handler(signal, frame):
        print('Cleaning up...')
        gc.collect()
        print('Bye.')
        sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.pause()

它可能是无限循环,也可能只是一些计算花费了太多时间,为了完整起见,请您发布代码?

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

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