Long intervals during resource iteration can lead to issues

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

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

2026年9月25日 から。

  • #205 @AdrianAtZyte による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
api

調査の方向性

job.items.iter(count=take, meta='_key') が使用するリソース収集のエントリーポイントから始め、use_msgpack=False と3分間の遅延を使って JSON ケースを再現します。遅延した取得の間、反復リクエストがどのように count を維持するかを追跡します。完了条件は、イテレータが要求された上限を超えずにその上限で停止することであり、該当する場合は、その動作をリポジトリの既存テストでカバーします。

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

説明

bug

Hello.

Recently there was this issue https://github.com/scrapinghub/python-scrapinghub/issues/121 for which a batch read workaround was implemented. I am now experiencing from what I believe to be same or similar issue but now while using JSON instead of msgpack. Basically when I do for item in job.items.iter(..., count=X, ...): if there are long intervals during iteration the count can end up being ignored. I was able to reproduce it with the following snippet:

sh_client = ScrapinghubClient(APIKEY, use_msgpack=False)
take = 10_000
job_id = '168012/276/1'
for i, item in enumerate(sh_client.get_job(job_id).items.iter(count=take, meta='_key')):
    print(f'\r{i} ({item["_key"]})', end='')

    if i == 3000:
        print('\nsleeping')
        time.sleep(60*3)
    
    if i > take:
        print('\nWTF')
        break

With the sleep part removed the WTF section does not fire and the iterator stops on 168012/276/1/9999th item.

This seem to be more of a ScrapyCloud API platform problem but I am reporting it here to track nonetheless.

For now I am assuming resource/collections iteration is not robust if any delays are possible client side during retrieval (I haven't tested any other potential issues) and I will try either preloading all at once (.list()) or using .list_iter() when makes sense as a habit.

主要言語
Python
スター
204
フォーク
62
平均マージ
6分
マージ済み PR(30日)
2

環境構築

はじめの一歩

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

scrapinghub/python-scrapinghub のほかの issue

scrapinghub/python-scrapinghub の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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