Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 5-second timeout to WordNet alternatives on creating reserved-w…

…ord models #501 [Marcel Molina]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@455 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 652f1ef02fdf75e8e971971707b3d5861d06b8be 1 parent 53088c4
@dhh dhh authored
Showing with 11 additions and 5 deletions.
  1. +2 −0  railties/CHANGELOG
  2. +9 −5 railties/bin/generate
View
2  railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added 5-second timeout to WordNet alternatives on creating reserved-word models #501 [Marcel Molina]
+
* Fixed binding of caller #496 [Alexey]
View
14 railties/bin/generate
@@ -6,14 +6,18 @@ ARGV.shift unless ARGV.empty? or not ['--help', '-h'].include?(ARGV[0])
def find_synonyms(word)
require 'open-uri'
+ require 'timeout'
+
uri = "http://wordnet.princeton.edu/cgi-bin/webwn2.0?stage=2" +
"&word=%s&posnumber=1&searchtypenumber=2&senses=&showglosses=1"
- open(uri % word) do |stream|
- data = stream.read.gsub("&nbsp;", " ").gsub("<BR>", "")
- data.scan(/^Sense \d+\n.+?\n\n/m)
+ timeout(5) do
+ open(uri % word) do |stream|
+ data = stream.read.gsub("&nbsp;", " ").gsub("<BR>", "")
+ data.scan(/^Sense \d+\n.+?\n\n/m)
+ end
end
-rescue Exception
+rescue Timeout::Error, Exception
return nil
end
@@ -66,4 +70,4 @@ end_usage
#{$0} login
end_usage
exit 0
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.