Following is a simple working script for describe my issue.
# 1.cr
require "selenium"
driver = Selenium::Driver.for(:chrome, base_url: "http://localhost:9515")
def ready?(driver)
begin
driver.status.ready?
rescue Socket::ConnectError
false
end
end
def run(driver)
if !ready?(driver)
driver_paths = ["/usr/local/bin/chromedriver", "/usr/bin/chromedriver"]
driver_path = driver_paths.each do |path|
break path if File.executable? path
end
if driver_path.nil?
abort "#{driver_paths.join(" or ")} not exists! Please install correct version Selenium driver for Chrome before continue, exit ..."
end
service = Selenium::Service.chrome(driver_path: driver_path)
driver = Selenium::Driver.for(:chrome, service: service)
end
options = Selenium::Chrome::Capabilities::ChromeOptions.new
options.args = ["--headless"]
capabilities = Selenium::Chrome::Capabilities.new
capabilities.chrome_options = options
new_session = driver.create_session(capabilities)
cookie_manager = Selenium::CookieManager.new(command_handler: new_session.command_handler, session_id: new_session.id)
cookie_manager.delete_all_cookies
new_session.navigate_to("https://www.bing.com/")
new_session.delete
end
spawn run(driver)
sleep 5
When i run this script the first time, with crystal run 1.cr, I can ensure the chromedriver started correctly use htop, as following screenshot, chromedriver started with 5 subprocess, we assume this is the expected correct result.
Then,when i ran crystal run 1.cr again, a new chromedriver sub-process was created, but never release the resource.
One more process created every time when i ran crystal run 1.cr again and again, will cause memory resources run out.
Perhaps this is not a issue about selenium.cr, anyway, i create this issue here for help.
Following is a simple working script for describe my issue.
When i run this script the first time, with
crystal run 1.cr
, I can ensure the chromedriver started correctly use htop, as following screenshot, chromedriver started with 5 subprocess, we assume this is the expected correct result.Then,when i ran
crystal run 1.cr
again, a new chromedriver sub-process was created, but never release the resource.One more process created every time when i ran
crystal run 1.cr
again and again, will cause memory resources run out.Perhaps this is not a issue about selenium.cr, anyway, i create this issue here for help.
Thanks.