How do I increase the stack size in python(如何增加python中的堆栈大小)
问题描述
我有一个使用定制 DLL 的 python 程序.此 DLL 由于堆栈溢出而崩溃.这种溢出不是由于递归函数坏了,而是由于使用 alloca() 在堆栈上进行了大量分配.
I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().
我想增加堆栈大小以消除此错误.有没有办法做到这一点?
I want to increase stack size to get rid of this error. Is there any way to do this?
推荐答案
AFAIK 程序只能更改新线程或进程的堆栈大小(Windows 的 CreateThread 函数,例如).由于 Python(以及 Python 的 Win32 API)没有公开此类功能,因此您应该将堆栈分配替换为堆内存.还是有使用堆栈的特定原因?如果您真的必须使用 alloca
,您可能需要创建一个单独的线程来执行 DLL 代码(我认为这太过分了).
AFAIK a program can only change the stack size of new threads or processes (Windows' CreateThread function, for example). As Python (and the Win32 API for Python) does not expose such functionality, you should rather replace the stack allocation with heap memory. Or is there a specific reason for using the stack?? If you really have to use alloca
you might want to create a separate thread for execution of DLL code (which is overkill I think).
更正 - Python 允许在创建新线程时设置堆栈大小(请参阅 thread.stack_size)
Correction - Python does allow for setting the stack size when creating new threads (see thread.stack_size)
这篇关于如何增加python中的堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何增加python中的堆栈大小


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