Skip to content

Instantly share code, notes, and snippets.

@phansch
Created November 27, 2017 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phansch/3df73b4ae657c317611766040db3581e to your computer and use it in GitHub Desktop.
Save phansch/3df73b4ae657c317611766040db3581e to your computer and use it in GitHub Desktop.
Debugging stuck Ruby processes
# Use this to get the stacktrace of any ruby process by calling kill -USR1 <pid>
# For rspec, put this in the spec_helper.rb, for rails in some initializer.
puts "ruby process pid: #{Process.pid}"
trap 'USR1' do
threads = Thread.list
puts
puts "=" * 80
puts "Received USR1 signal; printing all #{threads.count} thread backtraces."
threads.each do |thr|
description = thr == Thread.main ? "Main thread" : thr.inspect
puts
puts "#{description} backtrace: "
puts thr.backtrace.join("\n")
end
puts "=" * 80
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment