python , 使用 ulimit 启动外部程序

python , launch an external program with ulimit

我需要从我的 python 脚本启动一个外部程序。 这个程序崩溃了,所以我需要从中获取核心转储。

我能做什么?

查看 python resource 模块。它会让你设置核心文件的大小等,就像 ulimit 命令一样。具体来说,你想做类似

的事情
resource.setrlimit(resource.RLIMIT_CORE, <size>)

在启动目标程序之前。

我对用法的猜测(我自己没有做过)是:

import resource
import subprocess

resource.setrlimit(resource.RLIMIT_CORE, 
                   (resource.RLIM_INFINITY,
                    resource.RLIM_INFINITY))
command = 'command line to be launched'
subprocess.call(command)
# os.system(command) would work, but os.system has been deprecated
# in favor of the subprocess module