package main
import (
"yangsheng/models"
//"fmt"
"runtime"
//"time"
//"os"
)
func getinfo(id int,url string,a,b chan bool) {
a<-true
isok:=false
defer func() {
b <-isok
}()
info:=models.GetInfo(url)
if len(info["Title"]) > 0 {
var inmodel models.Info
var durls models.Deurls
inmodel.Url = info["Url"]
if inmodel.Read("title") !=nil {
inmodel.Title = info["Title"]
inmodel.Content = info["Content"]
_,err :=inmodel.Insert()
if err == nil {
durls.Id = id
durls.Status = 1
durls.Update("Status")
} else {
}
}
} else {
}
isok=true
}
func main() {
NCPU := runtime.NumCPU()
runtime.GOMAXPROCS(NCPU)
models.Init()
details :=new(models.Deurls)
var list []*models.Deurls
a :=make(chan bool,10)
b :=make(chan bool,1)
for i:=0;i<10;i++ {
details.Query().OrderBy("-id").Limit(i*2000,2000).All(&list)
for _,v := range list {
go getinfo(v.Id,v.Url,a,b)
}
}
for j:=0;j<20000;j++ {
<-b
<-a
}
close(a)
close(b)
}
我这段代码,是用来采集数据的。总共有2万条数据。运行一会,他就提示以下错误。
有疑问加站长微信联系(非本文作者)