作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
似乎我的某个脚本总是出现此错误:
/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/
我是一名优秀的程序员,十分优秀!