如果 RAM 接近饱和,如何终止 Python 进程(Anaconda on windows)?
how to kill a Python process (Anaconda on windows) if the RAM is close to be saturated?
我有一个简单的问题。
我经常 运行 在 pandas 中使用大型数据集进行复杂计算。有时 python 继续使用 RAM,直到一切都饱和,我的电脑基本上崩溃了。我在 windows 机器上使用 Anaconda 发行版。
是否可以设置一个阈值(例如 98%),如果 RAM 使用率超过该阈值,则应重新启动内核或终止进程?
Unix系统上好像比较容易(https://docs.python.org/2/library/resource.html#resource.setrlimit). However, for windows systems there does not seem to be an internal python way of limiting the amount of memory. You will then have to rely on the Windows API. As far as I can tell from this answer, you would be best off creating a Job object, and associate it with the python process. Then you would use JOB_OBJECT_LIMIT_JOB_MEMORY
to limit the memory of the process. Or possibly you can get away with using SetProcessWorkingSetSize.
我有一个简单的问题。
我经常 运行 在 pandas 中使用大型数据集进行复杂计算。有时 python 继续使用 RAM,直到一切都饱和,我的电脑基本上崩溃了。我在 windows 机器上使用 Anaconda 发行版。
是否可以设置一个阈值(例如 98%),如果 RAM 使用率超过该阈值,则应重新启动内核或终止进程?
Unix系统上好像比较容易(https://docs.python.org/2/library/resource.html#resource.setrlimit). However, for windows systems there does not seem to be an internal python way of limiting the amount of memory. You will then have to rely on the Windows API. As far as I can tell from this answer, you would be best off creating a Job object, and associate it with the python process. Then you would use JOB_OBJECT_LIMIT_JOB_MEMORY
to limit the memory of the process. Or possibly you can get away with using SetProcessWorkingSetSize.