我完全不熟悉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:[email protected](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
,永不返回。