如何在python中增加堆栈大小 [英] How do I increase the stack size in python

查看:2810
本文介绍了如何在python中增加堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用自定义DLL的python程序。这个DLL由于堆栈溢出而崩溃。这个溢出不是由于递归函数变坏,而是使用alloca()对堆栈进行大量分配。



我想增加堆栈大小以摆脱这个错误。有没有办法这样做?

解决方案

AFAIK程序只能改变新线程或进程的堆栈大小(Windows CreateThread 功能,例如)。由于Python(和Python的Win32 API)不会公开此类功能,所以您应该使用堆内存替换堆栈分配。还是有使用堆栈的具体原因?如果你真的使用来使用 alloca ,那么你可能需要创建一个单独的线程来执行DLL代码(这是我认为的) p>

编辑:更正 - Python确实允许在创建新线程时设置堆栈大小(请参阅 thread.stack_size


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 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).

EDIT: Correction - Python does allow for setting the stack size when creating new threads (see thread.stack_size)

这篇关于如何在python中增加堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆