Setting stacksize in a python script(在 python 脚本中设置堆栈大小)
问题描述
我正在将 csh 脚本转换为 python 脚本.该脚本调用了一个需要非常大堆栈的内存密集型可执行文件,因此 csh 脚本将堆栈大小设置为无限制:
I am converting a csh script to a python script. The script calls a memory-intensive executable which requires a very large stack, so the csh script sets the stacksize to unlimited:
limit stacksize unlimited
当我尝试在 python 中重现这个脚本时,我以一种非常幼稚的方式执行它们,使用 os.system
,例如:
When I try to reproduce this script in python, I execute them in a very naive manner, using os.system
, e.g.:
os.system('some_executable')
但我不知道如何告诉操作系统以无限堆栈大小运行这些可执行文件.有没有办法为 python 脚本中的调用指定堆栈大小?我应该使用一些低级系统调用吗?是否有一个模块(类似于shutil)来控制它?
But I do not know how to tell the OS to run these executables with unlimited stacksize. Is there a way to specify stacksize for calls within a python script? Is there some low-level system call that I should be using? And is there a module (similar to shutil) which controls this?
推荐答案
如果需要,您可以使用 shell 的 (u)limit 命令:
You can just use the (u)limit command of your shell, if you want:
os.system('ulimit -s unlimited; some_executable')
或者(可能更好)使用 resource.setrlimit:
Or (probably better) use resource.setrlimit:
resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
这篇关于在 python 脚本中设置堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 python 脚本中设置堆栈大小


基础教程推荐
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01