Ruby headless watir-webdriver Xvfb 僵尸

标签 ruby watir-webdriver centos6 headless xvfb

我有两个应用程序在一个服务器上运行,它们执行 headless (headless)浏览任务。每次浏览时,Xvfb 进程并没有死,而是变成了僵尸。我可以用以下脚本确认这一点。

require 'headless'
require 'watir-webdriver'
require 'yaml'

zombies_at_start = `ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'`.split("\n").count

5.times do
  begin
    d = YAML.load_file("/path/to/config/headless.yml")['build_number'] #=> "98"
    h = Headless.new(:display => d) 
    h.start
    b = Watir::Browser.new :firefox
    b.goto 'http://google.com'
    sleep(0.5)
  ensure
    b.close
    h.destroy
  end
  sleep(0.5)
end

zombies_at_end = `ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'`.split("\n").count

puts "Created #{zombies_at_end - zombies_at_start} more zombies." 
#=> Created 5 more zombies.

为什么?我该如何解决这个问题?


版本信息:

  • xorg-x11-server-Xvfb-1.15.0-26.el6.centos.i686
  • CentOS 6.5 版(最终版)
  • ruby-2.0.0-p353
  • rvm 1.25.25
  • selenium-webdriver (2.45.0, 2.44.0)
  • watir-webdriver (0.7.0)
  • headless (headless)(2.1.0)

最佳答案

更新: A pull request提交给 Headless 等待默认被接受。哇!


headless (headless) gem changed the way it starts, stops (kills) and verifies the Xvfb process .虽然我不完全确定为什么,但在 CentOS 6 上,这会导致进程僵尸化。由于 .destroy 之前没有引起问题,它一定与 headless 启动 Xvfb 进程(同时重写)的方式有关。

但是gem同时引入了.destroy_sync,等待进程死亡,不产生僵尸。

require 'headless'
require 'watir-webdriver'
require 'yaml'

zombies_at_start = `ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'`.split("\n").count

5.times do
  begin
    d = YAML.load_file("/path/to/config/headless.yml")['build_number'] #=> "98"
    h = Headless.new(:display => d) 
    h.start
    b = Watir::Browser.new :firefox
    b.goto 'http://google.com'
    sleep(0.5)
  ensure
    b.close
    # h.destroy
    h.destroy_sync
  end
  sleep(0.5)
end

zombies_at_end = `ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'`.split("\n").count

puts "Created #{zombies_at_end - zombies_at_start} more zombies." 
#=> Created 0 more zombies.

关于Ruby headless watir-webdriver Xvfb 僵尸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30754358/

相关文章:

Ruby 将字符串转换为哈希

ruby - 使用 Watir 保存屏幕截图时,png 为空或 0kb

selenium-webdriver - 在 watir 中自动下载文件

Apache 2.2 PHP-FPM,浏览器中禁止接收 403 的 php 文件

ruby-on-rails - ruby /Rails : Best way to loop through a csv and set flag when new person is found

ruby - 模运算符 Ruby : Why am I getting "undefined method ` %' for 1..100:Range"? 的问题

ruby-on-rails - controller#index 方法显示路由错误

ruby - Watir-webdriver 如何不先访问 LAST 匹配元素?

在 CentOS 上安装 MongoDB

linux - 循环遍历用户文件夹并删除文件夹