[Bug]: AsyncUrlSeeder.urls() always idles ~5 s after the last sitemap URL (worker polls queue.get() with a 5 s timeout)

オープン
#2,509 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@PiUnknown がすでに取り組んでいます。

2026年11月7日 から。

  • #2511 @anubhavlal07 による — オープン
  • #2512 @PiUnknown による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

Start in crawl4ai/async_url_seeder.py around the worker loop at line 486 and trace how producer completion and the max_urls early-stop path interact with the queue. Compare the same timeout pattern in extract_head_for_urls(). The issue suggests sentinels or waiting on both events; done means workers wake promptly after production ends without breaking early-stop behavior, with coverage for both paths.

索引モデルが issue の本文から書いたものです。

説明

🐞 Bug 🩺 Needs Triage
crawl4ai version

0.9.4 (the same code is on main today)

Expected behavior

AsyncUrlSeeder.urls() returns as soon as the producer has yielded the last URL and the workers have processed the queue.

Current behavior

Every call takes about 5 seconds longer than reading the sitemap. In urls() each worker loops:

if queue.empty() and producer_done.is_set():
    break
try:
    url = await asyncio.wait_for(queue.get(), 5)
except asyncio.TimeoutError:
    continue

(crawl4ai/async_url_seeder.py, line 486 on main.) A worker that finds the queue empty while the producer is still running parks in queue.get() with a 5 s timeout. When the producer then finishes without putting another item, nothing wakes that worker, so it sits out the full 5 s before it re-checks producer_done. With extract_head=False and live_check=False the workers do almost no work, so this wait is nearly the whole cost of the call.

In our crawler (sitemap source only, extract_head=False, concurrency=5) the wait was about 13 % of total crawl time per site across 23 real sites, and the first page started after 9.5 s instead of 6.1 s (median) once the wait was gone.

Steps to reproduce
import asyncio, time
from crawl4ai import AsyncUrlSeeder, SeedingConfig

async def main():
    async with AsyncUrlSeeder() as seeder:
        started = time.perf_counter()
        urls = await seeder.urls("https://www.python.org", SeedingConfig(source="sitemap", extract_head=False, force=True))
        print(len(urls), "URLs in", round(time.perf_counter() - started, 1), "s")

asyncio.run(main())

Timing the producer separately (iterating seeder._from_sitemaps(domain, "*", force=True)) shows the sitemap itself is read about 5 s faster than urls() returns.

Possible fix

Wake the workers when the producer finishes, for example with one sentinel per worker:

# producer, in its finally block
producer_done.set()
for _ in range(concurrency):
    await queue.put(None)

# worker
url = await queue.get()
if url is None:
    queue.task_done()
    break

(The max_urls early-stop path that flushes the queue would need to keep the sentinels, or use asyncio.wait on queue.get() and producer_done.wait() instead of the polling timeout.) extract_head_for_urls() has the same pattern with a 1 s timeout.

OS

Linux (Debian, Docker), macOS

Python version

3.15

主要言語
Python
スター
87.2k
フォーク
9.1k
平均マージ
1日 6時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

unclecode/crawl4ai のほかの issue

unclecode/crawl4ai の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。