rubymultithreadingruby-on-rails-4byebug

Rails using byebug inside a proc?


I am trying to use byebug/debugger inside a proc that gets called later with threads, but its not working. So how can I Debug code inside a proc?


Solution

  • You have to ensure that the thread inside which you are adding the breakpoint eventually calls join.

    e.g.:

    myproc = Proc.new do
      Thread.new do
        require 'pry'; binding.pry
      end.join
    end
    
    myproc.call
    

    will stop at the breakpoint.

    Whereas

    myproc = Proc.new do
      Thread.new do
        require 'pry'; binding.pry
      end
    end
    
    myproc.call
    

    will not