I get this error: RuntimeError (detected cyclic dependency on autoload of persistent applications
when i am multithreading. Here is my code below. Why is this happening? The reason I'm trying to use multithreading is because I am writing an HTML cleanup application. The Nokogiri :: HTML call (open ()) is a synchronous blocking call that returns 1 second and I have 100,000 + pages to visit, so I'm trying to run multiple threads to solve this problem. Is there a better way to do this?
class ToolsController < ApplicationController def getWebsites t1=Thread.new{func1()} t2=Thread.new{func1()} t3=Thread.new{func1()} t4=Thread.new{func1()} t5=Thread.new{func1()} t6=Thread.new{func1()} t1.join t2.join t3.join t4.join t5.join t6.join end def func1 puts Thread.current apps = Apps.order("RANDOM()").where("apps.website IS NULL").take(1) while apps.size == 1 do app = apps[0] puts app.name puts app.iTunes doc = Nokogiri::HTML(open(app.iTunes)) array = doc.css('div.app-links a').map { |link| url = link['href'] url = Domainatrix.parse(url) url.domain + "." + url.public_suffix } array.uniq! if (array.size > 0) app.website = array.join(', ') puts app.website else app.website = "NONE" end app.save apps = Apps.order("RANDOM()").where("apps.website IS NULL").take(1) end end end
source share