gpt4 book ai didi

Ruby 探查器堆栈级别太深错误

转载 作者:数据小太阳 更新时间:2023-10-29 07:23:14 24 4
gpt4 key购买 nike

似乎我的某个脚本总是出现此错误:

/Users/amosng/.rvm/gems/ruby-1.9.3-p194/gems/ruby-prof-0.11.2/lib/ruby-prof/profile.rb:25: stack level too deep (SystemStackError)

有没有人遇到过这个错误?可能是什么原因造成的,我可以做些什么来防止它发生?

我使用命令运行我的 ruby​​-prof 脚本

ruby-prof --printer=graph --file=profile.txt scraper.rb -- "fall 2012"

编辑 如果重要的话,我使用的是 Mac OS X。不幸的是,执行 ulimit -s 64000 似乎没有多大帮助。以下是 ulimit -a 给出的内容:

$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 64000
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) unlimited

编辑2

Andrew Grimm 的解决方案可以很好地防止 ruby​​-prof 崩溃,但分析器似乎有其自身的问题,因为我看到一个进程所花费的总时间的百分比为 679.50%...

最佳答案

一种解决方法是 turn tail call optimization on .

以下是在 TCO 开启时有效但在 TCO 关闭时无效的示例。

RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}

def countUpTo(current, final)
puts current
return nil if current == final
countUpTo(current+1, final)
end

countUpTo(1, 10_000)

关于Ruby 探查器堆栈级别太深错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11692559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com