deivid-rodriguez/pry-byebug

using pry-byebug with selenium - deadlock error and unable to step through my code

gartha1 opened this issue · 2 comments

When I try using pry-byebug, I find I am unable to step through my code.

It goes into some internal code not written by me, and then gives an error about deadlock.

For anybody unfamiliar with Selenium, it is a library that lets a person programmatically control a web browser. I am using Mac osx. I had to do $gem install selenium-webdriver(which I guess you know). And I had to install a chrome web driver which I did with $brew tap homebrew/cask and $brew cask install chrome driver. Selenium is running fine for me.

The program below demonstrates an issue I'm having with pry-byebug.

Apples-MBP:aa apple$ ls -l
total 24
-rw-r--r--  1 apple  staff   17 29 Dec 03:52 Gemfile
-rw-r--r--  1 apple  staff  287 29 Dec 03:53 Gemfile.lock
-rw-r--r--  1 apple  staff  490 29 Dec 03:53 pbb_selenium_thing.rb
Apples-MBP:aa apple$ cat Gem file
gem 'pry-byebug'
Apples-MBP:aa apple$ bundle install
Using bundler 1.16.2
Using byebug 10.0.2
Using coderay 1.1.2
Using method_source 0.9.2
Using pry 0.11.3
Using pry-byebug 3.6.0
Bundle complete! 1 Gemfile dependency, 6 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Apples-MBP:aa apple$ cat pbb_selenium_thing.rb 
# https://stackoverflow.com/questions/53962313/in-ruby-i-cant-get-byebug-to-work-with-selenium?noredirect=1#comment94763217_53962313

    require 'selenium-webdriver'
    require 'pry'
    require 'pry-byebug'
 
    binding.pry
    
    driver = Selenium::WebDriver.for:chrome
    
    driver.navigate.to "http://google.com"
 
    puts driver.find_element(:tag_name, 'input');
    puts driver.find_element(:name, 'q');

    driver.find_element(:name, 'q').send_keys("asdf");
    #sleep 20

Apples-MBP:aa apple$ ruby pbb_selenium_thing.rb 
WARN: Unresolved specs during Gem::Specification.reset:
      ffi (>= 1.0.11, ~> 1.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.

From: /Users/apple/rubyselenium1/aa/pbb_selenium_thing.rb @ line 9 :

     4:     require 'pry'
     5:     require 'pry-byebug'
     6:  
     7:     binding.pry
     8:     
 =>  9:     driver = Selenium::WebDriver.for:chrome
    10:     
    11:     driver.navigate.to "http://google.com"
    12:  
    13:     puts driver.find_element(:tag_name, 'input');
    14:     puts driver.find_element(:name, 'q');

[1] pry(main)> step

From: /usr/local/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver.rb @ line 86 Selenium::WebDriver.for:

    85: def self.for(*args)
 => 86:   WebDriver::Driver.for(*args)
    87: end

[1] pry(Selenium::WebDriver)> step

From: /usr/local/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb @ line 42 Selenium::WebDriver::Driver.for:

    41: def for(browser, opts = {})
 => 42:   case browser
    43:   when :chrome
    44:     Chrome::Driver.new(opts)
    45:   when :internet_explorer, :ie
    46:     IE::Driver.new(opts)
    47:   when :safari
    48:     Safari::Driver.new(opts)
    49:   when :phantomjs
    50:     PhantomJS::Driver.new(opts)
    51:   when :firefox, :ff
    52:     Firefox::Driver.new(opts)
    53:   when :edge
    54:     Edge::Driver.new(opts)
    55:   when :remote
    56:     Remote::Driver.new(opts)
    57:   else
    58:     raise ArgumentError, "unknown driver: #{browser.inspect}"
    59:   end
    60: end

[1] pry(Selenium::WebDriver::Driver)> step

From: /usr/local/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb @ line 44 Selenium::WebDriver::Driver.for:

    41: def for(browser, opts = {})
    42:   case browser
    43:   when :chrome
 => 44:     Chrome::Driver.new(opts)
    45:   when :internet_explorer, :ie
    46:     IE::Driver.new(opts)
    47:   when :safari
    48:     Safari::Driver.new(opts)
    49:   when :phantomjs
    50:     PhantomJS::Driver.new(opts)
    51:   when :firefox, :ff
    52:     Firefox::Driver.new(opts)
    53:   when :edge
    54:     Edge::Driver.new(opts)
    55:   when :remote
    56:     Remote::Driver.new(opts)
    57:   else
    58:     raise ArgumentError, "unknown driver: #{browser.inspect}"
    59:   end
    60: end

[1] pry(Selenium::WebDriver::Driver)> step

From: /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb @ line 40 Kernel#require:

    35:   #
    36:   # The normal <tt>require</tt> functionality of returning false if
    37:   # that file has already been loaded is preserved.
    38: 
    39:   def require path
 => 40:     RUBYGEMS_ACTIVATION_MONITOR.enter
    41: 
    42:     path = path.to_path if path.respond_to? :to_path
    43: 
    44:     if spec = Gem.find_unresolved_default_spec(path)
    45:       Gem.remove_unresolved_default_spec(spec)

[1] pry(main)> step

From: /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb @ line 184 MonitorMixin#mon_enter:

    183: def mon_enter
 => 184:   if @mon_owner != Thread.current
    185:     @mon_mutex.lock
    186:     @mon_owner = Thread.current
    187:     @mon_count = 0
    188:   end
    189:   @mon_count += 1
    190: end

[1] pry(#<Monitor>)> step

From: /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb @ line 185 MonitorMixin#mon_enter:

    183: def mon_enter
    184:   if @mon_owner != Thread.current
 => 185:     @mon_mutex.lock
    186:     @mon_owner = Thread.current
    187:     @mon_count = 0
    188:   end
    189:   @mon_count += 1
    190: end

[1] pry(#<Monitor>)> step
before_session hook failed: ThreadError: deadlock; recursive locking
/usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb:185:in `lock'
(see _pry_.hooks.errors to debug)
[1] pry(#<Monitor>)> quit
Traceback (most recent call last):
	29: from pbb_selenium_thing.rb:9:in `<main>'
	28: from /usr/local/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver.rb:86:in `for'
	27: from /usr/local/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
	26: from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:40:in `require'
	25: from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb:186:in `mon_enter'
	24: from /usr/local/lib/ruby/gems/2.5.0/gems/byebug-10.0.2/lib/byebug/context.rb:98:in `at_line'
	23: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:63:in `at_line'
	22: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:111:in `resume_pry'
	21: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:27:in `run'
	20: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:27:in `catch'
	19: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:28:in `block in run'
	18: from /usr/local/lib/ruby/gems/2.5.0/gems/byebug-10.0.2/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
	17: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:28:in `block (2 levels) in run'
	16: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/byebug/processors/pry_processor.rb:113:in `block in resume_pry'
	15: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:348:in `repl'
	14: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:38:in `start'
	13: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/input_lock.rb:79:in `with_ownership'
	12: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/input_lock.rb:61:in `__with_ownership'
	11: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:38:in `block in start'
	10: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:67:in `repl'
	 9: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:67:in `loop'
	 8: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:68:in `block in repl'
	 7: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/repl.rb:108:in `read'
	 6: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/indent.rb:394:in `correct_indentation'
	 5: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/terminal.rb:8:in `screen_size'
	 4: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/terminal.rb:33:in `actual_screen_size'
	 3: from /usr/local/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/terminal.rb:47:in `screen_size_according_to_io_console'
	 2: from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:40:in `require'
	 1: from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb:185:in `mon_enter'
/usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/monitor.rb:185:in `lock': deadlock; recursive locking (ThreadError)
Apples-MBP:aa apple$ 

This shows what happens if I use 'next' rather than 'step'.

It doesn't stop at each put statement. (which is what I want to do).

So either way, step or next, it doesn't work or doesn't do what I'd like.

Apples-MBP:aa apple$ ls -l
total 24
-rw-r--r--  1 apple  staff   17 29 Dec 03:52 Gemfile
-rw-r--r--  1 apple  staff  287 29 Dec 03:53 Gemfile.lock
-rw-r--r--  1 apple  staff  490 29 Dec 03:53 pbb_selenium_thing.rb
Apples-MBP:aa apple$ cat Gemfile
gem 'pry-byebug'
Apples-MBP:aa apple$ cat pbb_selenium_thing.rb 
# https://stackoverflow.com/questions/53962313/in-ruby-i-cant-get-byebug-to-work-with-selenium?noredirect=1#comment94763217_53962313

    require 'selenium-webdriver'
    require 'pry'
    require 'pry-byebug'
 
    binding.pry
    
    driver = Selenium::WebDriver.for:chrome
    
    driver.navigate.to "http://google.com"
 
    puts driver.find_element(:tag_name, 'input');
    puts driver.find_element(:name, 'q');

    driver.find_element(:name, 'q').send_keys("asdf");
    #sleep 20

Apples-MBP:aa apple$ ruby pbb_selenium_thing.rb 
WARN: Unresolved specs during Gem::Specification.reset:
      ffi (>= 1.0.11, ~> 1.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.

From: /Users/apple/rubyselenium1/aa/pbb_selenium_thing.rb @ line 9 :

     4:     require 'pry'
     5:     require 'pry-byebug'
     6:  
     7:     binding.pry
     8:     
 =>  9:     driver = Selenium::WebDriver.for:chrome
    10:     
    11:     driver.navigate.to "http://google.com"
    12:  
    13:     puts driver.find_element(:tag_name, 'input');
    14:     puts driver.find_element(:name, 'q');

[1] pry(main)> next
#<Selenium::WebDriver::Element:0x00007fb4a7bff8e8>
#<Selenium::WebDriver::Element:0x00007fb4a7b0c3c8>
Apples-MBP:aa apple$ 

I have a similar issue while using pry-byebug with pry-remote on MacOS. If I try to use finish, step, or next, it gets stuck at a call to teardown in PryRemote::Server#run

[36] pry(#<Admin::VersionsController>)> finish
From: /usr/local/lib/ruby/gems/2.6.0/gems/pry-remote-0.1.8/lib/pry-remote.rb @ line 211 PryRemote::Server#run:

    206: def run
    207:   setup
    208:
    209:   Pry.start(@object, @options.merge(:input => client.input_proxy, :output => client.output))
    210: ensure
 => 211:   teardown
    212: end