Reputation: 2328
I want something to stop a Pry command but I don't want to exit to my shell.
Control+C is not what I'm looking for. I'm not trying to exit out of a loop or out of the entire session. I simply want to return to the Pry prompt if I run a line of code that takes a long time.
Upvotes: 0
Views: 377
Reputation: 18843
This is possible if you started Pry from the command line (that is, by just running pry
), but probably not if you're inside a binding.pry
during another process.
If you started Pry directly, it set up signal handlers and will catch Control+C to return you to the REPL. IRB does the same thing, depending on its ignore_sigint
setting.
But, if you're running inside another process, that process may have set up its own signal handlers. E.g., both rspec
and rails s
watch for Control+C to perform a graceful shutdown. Trying to stop a command inside one of those processes will actually leave Pry open, but perform the process's shutdown work, so as soon as you exit Pry, you're dumped back to the command line.
You can in your Pry session set up your own signal handler, e.g.:
Signal.trap('SIGINT') { puts 'Trapped' }
And there may be something exceedingly clever you can do there to move execution back to the Pry REPL, but it's almost certain to wreak havoc with other handlers that might be in place.
Upvotes: 1