-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When peeking via SIGQUIT, every 'require' causes an error #52
Comments
+1 |
I just did bundle update to pry-rescue 1.3.1 and interception 0.4. It's still failing, but the output changed a bit:
Not really sure what the last line means, but any command after this fails. Can provide more info if you tell me where to look. |
I found what seems to be the root cause, which is that Ruby has a very limited ability to perform I/O (in this case, apparently including reading files via http://www.mikeperham.com/2013/02/23/signal-handling-with-ruby/ There are some workarounds for libraries like Foreman (see ddollar/foreman#332 for their pipe-based solution), but they don't have to interrupt arbitrary code in its current execution state. I don't know enough about the details of pry and ruby execution state to say whether there might be a workaround for pry-rescue. This looks like a tough one. Any ideas? |
Is there anything we can do in a signal handler to escape? e.g. |
Update: Guard has tackled this issue as well using a separate thread. I don't think it has access to the current binding, but that's a lot to ask. guard/guard#571 |
As done by @mperham the trap should just add signals to a queue (an array or, better, a queue*) and then you can keep a loop inside a thread that will pop from the event queue. * the queue is better because avoids using sleep by using the blocking |
Similar backtrace: [5] pry(Timeout)> yield(0)
^\Preparing to peek via pry!
ThreadError: can't be called from trap context
from /data/ruby/lib/ruby/2.4.0/monitor.rb:187:in `lock'
[6] pry(Timeout)> bt
=> nil
[7] pry(Timeout)> backtrace
--> #0 #<Class:Timeout>.timeout(sec#Float, klass#NilClass, message#NilClass) at /spool/ruby/lib/ruby/2.4.0/timeout.rb:77 And the full trace: #<ThreadError: can't be called from trap context>
/data/ruby/lib/ruby/2.4.0/monitor.rb:187:in `lock'
/data/ruby/lib/ruby/2.4.0/monitor.rb:187:in `mon_enter'
/data/ruby/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
/data/ruby/lib/ruby/gems/2.4.0/gems/pry-rescue-1.4.5/lib/pry-rescue/peek.rb:10:in `peek!'
(and then mixed code with gems: event-machine, aspector, timeout) |
I have had poor luck with getting peek to work via Ctrl-\ since every
require
statement seems to cause an error, worst of all being those in Pry:before_session
hooks and those from CodeRay autoloads. As a result, I never get to see the code I'm trying to peek at, nor can I explore the stack or the other stuff. I really like this functionality and would love to make this work, but ifrequire
doesn't work I don't understand how it ever did.Here are some example sessions:
(hangs)
This is in Ruby 2.0 on OS X 10.9. Maybe there's something I don't have configured properly, but even a simple script that I break into with Ctrl-\ has this problem. I made a repo with this example (run main.rb and use Ctrl-\ or just run the test script and peek after it prints the first line of numbers):
https://github.com/zach/pry-rescue-peek-test
Why does this seem to work in other circumstances and yet I can't seem to make this work? Is this a Bundler-related issue?
The text was updated successfully, but these errors were encountered: