1

I have limited space on my machine. So, I am running a loop that goes to a website, logs in, follows a link and scrapes data. To limit the space being used, I call a function that closes and quits the webdriver. Then I open a new one, log in again and follow a different link. After 3 or 4 times I get the error when I call the driver.quit().

def close_driver(driver):
  driver.close()
  driver.quit()
  return

I haven't had this issue on my Mac but when I try to run it on IBM bluemix. I get the error:

OSError: [Errno 9] Bad file descriptor 
Lost Puppy
  • 19
  • 6

1 Answers1

1

Sometimes PhantomJS can run into these errors trying to close an instance that has already been closed. Instead of running both close() and quit(), just run quit(). quit() will do all necessary functions to properly close and exit the webdriver instance.

crookedleaf
  • 2,118
  • 4
  • 16
  • 38
  • 1
    I have the same problem, without using `driver.close()` but just `driver.quit()`. It seems there is a bug in the `quit` method. see https://github.com/seleniumhq/selenium/issues/3216 – Timotheus Pokorra Mar 10 '17 at 05:51
  • @TimotheusPokorra thouse should be resolved when you update your Selenium package to the newest version – crookedleaf Mar 10 '17 at 18:39
  • @TimotheusPokorra @crookedleaf I tried doing just `driver.quit()` . But it had the same result. I found a solution that worked for me via: http://stackoverflow.com/questions/25110624/how-to-properly-stop-phantomjs-execution Thanks to @leekaiinthesky `import signal driver.service.process.send_signal(signal.SIGTERM) # kill the specific phantomjs child proc driver.quit() # quit the node proc` – Lost Puppy Mar 11 '17 at 01:42
  • @LostPuppy this is actually pretty bad practice, but if it works, it works lol. Is your Selenium installation up to date? If so, running just `driver.quit()` should be sufficient. If it isn't up to date, and you are able to update it (it wont break anything), i'd highly recommend updating it. – crookedleaf Mar 13 '17 at 20:10
  • @LostPuppy: I finally realized that my code was calling driver.quit() twice, which explains my issue. thanks for the hints! – Timotheus Pokorra Mar 15 '17 at 06:20