题
我有一个红宝石脚本,它几Perforce的操作(通过脚本API),那么简单地结束时:
def foo()
...
end
def bar()
...
end
foo()
bar()
puts __LINE__
exit 0
#end of file
...和同时的 LINE 强>将打印出,过程不会结束,退出是否(0)是有或没有。这是红宝石1.8.6,主要是在Mac上,但我看到这个在PC上也是如此。
我做的通常谷歌闲逛,但希望有可能是经验的声音在这里风生水起。感谢。
解决方案
我不是Perforce的大家耳熟能详,但罪魁祸首可能是一个的就是停留在出于某种原因循环at_exit
方法。观察使用irb
行为,例如:
$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> at_exit { puts Time.now; sleep 10; puts Time.now }
=> #<Proc:0xb7656f64@(irb):2>
irb(main):003:0> exit
Fri Mar 12 19:46:25 -0500 2010
Fri Mar 12 19:46:35 -0500 2010
要确认一个at_exit
功能是否是导致进程挂起,你可以尝试挂钩到at_exit
。注意,#{caller}
将显示谁称为at_exit
堆栈跟踪:
def at_exit &block
@at_exit_counter ||= 0
puts "at_exit #{@at_exit_counter} called"
s = "Calling at_exit ##{@at_exit_counter} from #{caller}"
super { puts s; block.call() }
@at_exit_counter += 1
end
at_exit { puts "I'll never return"; sleep 1 while true; }
at_exit { puts 'I am about to leave.' }
def do_cleanup
puts "Cleaning..."
at_exit { puts 'Cleaning up before exit...' }
end
do_cleanup
,其输出:
at_exit 0 called at_exit 1 called Cleaning... at_exit 2 called Calling at_exit #2 from exitcheck.rb:14:in `do_cleanup'exitcheck.rb:18 Cleaning up before exit... Calling at_exit #1 from exitcheck.rb:10 I am about to leave. Calling at_exit #0 from exitcheck.rb:9 I'll never return
和永远不会返回。
不隶属于 StackOverflow