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 脚本中设置堆栈大小


基础教程推荐
- 在 Python 中将货币解析为数字 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01