Posted 6 months ago. Visible to the public.

How to get a backtrace if rspec (or any other ruby process) hangs with no output

If rspec hangs with no output and you dont get a backtrace neither with --backtrace nor by just killing it with crtl-c,
you can put the following in your spec/spec_helper.rb:

puts "rspec 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

then kill the process with kill -USR1 <the pid> and you get the backtrace.


By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Martin Schaflitzl
Last edit:
6 months ago
by Martin Schaflitzl
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Martin Schaflitzl to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more