Created
May 22, 2012 01:39
-
-
Save aselder/2766012 to your computer and use it in GitHub Desktop.
Test script demonstrating Nokogiri thread safety
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'nokogiri' | |
MS_ARRAY_SCHEMA = "http://schemas.microsoft.com/2003/10/Serialization/Arrays".freeze | |
def job | |
begin | |
data = Nokogiri::XML(open("file.xml")) | |
rows = data.xpath(".//xmlns:ArrayOfTicket/xmlns:Ticket") | |
rows.each do |row| | |
row.xpath(".//xmlns:Id").first | |
row.xpath(".//xmlns:DisplayPrice").first | |
row.xpath(".//xmlns:AvailableBlocks").first.xpath("a:int", {"a" => MS_ARRAY_SCHEMA}).collect{|elem| elem.text.to_i} | |
end | |
puts "OK" | |
rescue Nokogiri::XML::XPath::SyntaxError => ex | |
puts "XPath Syntax Error: #{ex}" | |
end | |
end | |
threads = (0...100).to_a.map {Thread.new {job}} | |
threads.each {|t| t.join} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment