简体   繁体   English

Ruby无头watir-webdriver Xvfb僵尸

[英]Ruby headless watir-webdriver Xvfb zombies

I have two apps running on a single server that perform headless browsing tasks. 我在一台服务器上运行了两个应用程序来执行无头浏览任务。 Each time one browses, the Xvfb process is not dying and instead becomes a zombie. 每次浏览时,Xvfb进程都不会死亡,而是成为一个僵尸。 I can confirm this with the following script. 我可以使用以下脚本确认这一点。

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.

Why? 为什么? How can I fix this? 我怎样才能解决这个问题?


Version info: 版本信息:

  • xorg-x11-server-Xvfb-1.15.0-26.el6.centos.i686 的xorg-X11-服务器的Xvfb,1.15.0-26.el6.centos.i686
  • CentOS release 6.5 (Final) CentOS 6.5版(最终版)
  • ruby-2.0.0-p353 红宝石2.0.0-P353
  • rvm 1.25.25 rvm 1.25.25
  • selenium-webdriver (2.45.0, 2.44.0) selenium-webdriver(2.45.0,2.44.0)
  • watir-webdriver (0.7.0) watir-webdriver(0.7.0)
  • headless (2.1.0) 无头(2.1.0)

UPDATE: A pull request submitted to Headless to wait by default was accepted. 更新:提交给Headless默认等待的拉取请求被接受。 Woo! 呜!


The gem headless changed the way it starts, stops (kills) and verifies the Xvfb process . 宝石无头改变了它的启动方式,停止(杀死)并验证了Xvfb进程 Though I'm not entirely sure why, but on CentOS 6 this causes the process to zombify. 虽然我不完全确定原因,但在CentOS 6上,这会导致流程僵尸化。 Since the .destroy wasn't causing issues previously, it must be related to the way headless starts the Xvfb process (which was re-written simultaneously). 由于.destroy以前没有引起问题,它必须与无头启动Xvfb进程(同时重写)的方式有关。

However, the gem simultaneously introduced .destroy_sync , which waits for the process to die, and does not create zombies. 然而,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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM