加线程delay

This commit is contained in:
2026-04-13 23:02:10 +08:00
parent ae001b82e6
commit c79192e2ce
2 changed files with 21 additions and 18 deletions
+3
View File
@@ -624,6 +624,7 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
cs.IsRunning = false cs.IsRunning = false
}) })
// 空循环等 normalChildCh,新数据到达后立即从 epoch 0 重新开始 // 空循环等 normalChildCh,新数据到达后立即从 epoch 0 重新开始
// 加 1000ms 睡眠避免 CPU 空转轮询
for { for {
select { select {
case gc, ok := <-c.normalChildCh: case gc, ok := <-c.normalChildCh:
@@ -641,6 +642,8 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
case <-c.stopCh: case <-c.stopCh:
// 收到停止信号 // 收到停止信号
return return
case <-time.After(1000 * time.Millisecond):
// 每 1000ms 检查一次,降低 CPU 占用
} }
} }
restartEpochLoop: restartEpochLoop: