-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Allow other threads like pry #142
Allow other threads like pry #142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/thread_lock_test.rb
Outdated
let(:output) { StringIO.new } | ||
let(:input) { InputTester.new } | ||
|
||
describe "when there's a other thread" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/a other/another/
1d89db7
to
50e0a07
Compare
Added and force pushed! |
Oh sorry, I overlooked that issue though, it seems it's fixed via this PR. #!/usr/bin/env ruby
require 'pry-byebug'
def test_thread
t = Thread.start do
$test_thread=:test
end
sleep 1
if $test_thread != :test
puts "test_thread failed!"
raise "Test thread failed to set $test_thread!"
else
puts "Test thread value: #{$test_thread}"
end
t.terminate
$test_thread=nil
end
binding.pry
nil Before (master, 8512acc)
After (This branch)
|
That's fantastic news! I'll be releasing 3.5.1 with this fix as soon as we get this merged. Just two final requests.
Again, thanks so much for fixing this, it feels great to get long standing issues like this one fixed! 😃 |
50e0a07
to
21dcb7c
Compare
Fixed and force pushed! |
Thanks so much! Just in case you want to have a look, this might be related to deivid-rodriguez/byebug#193 too. Obviously not the same since |
|
Sadly for me it still hangs when used with Capybara and PhantomJS. |
@jmuheim Could you give me a reproducible code? |
Yes, I created a branch of my current project: https://github.com/jmuheim/base/compare/playground/js_tests_hang_after_using_pry?expand=1 Just create a
If you remove the |
Interestingly, when adding |
I'm still not sure what is the cause but I can reproduce hanging once every three times. require 'capybara/poltergeist'
require 'capybara/dsl'
Capybara.app = Rack::Builder.new do
map "/" do
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
end
end.to_app
Capybara.default_driver = :poltergeist
Object.new.instance_eval do
extend Capybara::DSL
visit '/'
binding.pry
p page.text
page.driver.quit
end |
Thank you for investigating the issue, @mtsmfm! Is there any action required on my side? |
Finally, I found it isn't related to pry-byebug/pry/byebug. |
Could you try my fork to make sure the problem is fixed? |
Works perfectly! 👍 Thank you for the effort. |
This is a deal breaker. It makes it extremely harder to debug when dropping a A better way to deal with the original issue would be to opt-in to |
@yuki24 I have no idea about ideal default behavior though, I don't think it breaks a deal because pry doesn't lock: require 'pry'
require 'capybara/poltergeist'
require 'capybara/dsl'
Capybara.app = Rack::Builder.new do
map "/" do
run lambda { |env|
[200, {'Content-Type' => 'text/plain'}, ['OK']]
}
end
map "/hi" do
run lambda { |env|
binding.pry
[200, {'Content-Type' => 'text/plain'}, ['hi']]
}
end
end.to_app
Capybara.default_max_wait_time = 1
Capybara.default_driver = :poltergeist
Object.new.instance_eval do
extend Capybara::DSL
visit '/'
page.evaluate_script <<~JS
function() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", '/hi');
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.body.appendChild(document.createTextNode(xmlHttp.responseText));
}
}
xmlHttp.send(null);
}();
JS
assert_text 'hi' # expected to find text "hi" in "OK" (Capybara::ExpectationNotMet)
page.driver.quit
end IMO, timeout error is easier to understand than hanging. |
Stepping here again. This has made nearly impossible to use @mtsmfm I don't think timeout is desirable because it always requires you to tweak the timeout manually (which always risks from accidentally getting checked into source control). Plus, you never know how long you want to keep the pry console open for, and it's very destructive when the test runner actually closes the whole session while you are looking into something (and tweak timeout and re-run the whole test). What are your thoughts? There should at least be a global toggle for people who debug in a multi-threaded environment. |
Sometimes we want to run other threads in debugging and sometimes don't. As I described before, my opinions are:
You can easily lock on require 'bundler/setup'
require 'socket'
require 'pry-byebug'
# Put this configure in your .pryrc
Pry.config.hooks.add_hook(:before_session, :byebug_lock) do
Byebug.lock
end
Thread.new do
while true
sleep 1
puts 'hi'
end
end
# You don't see "hi" message on pry console
binding.pry
nil |
Thank you for creating awesome gem!
I often use this gem with capybara.
In capybara, generally test server is booted in other thread.
I noticed that
binding.pry
locks other thread if I installpry-byebug
whereas it doesn't lock if I havepry
only.I found we can unlock by
Byebug.unlock
though,I think it's good to follow Pry's default, in other words, I think we shouldn't change default behavior as far as possible.
What do you think?