Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Is there a way to deal with variable sized iterables?

未关闭
#64 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
40/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

首先定位 progress_bar 的实现以及 issue 中描述的 self.total = len(gen) if total is None else total 这一行。重现提供的 Timer 示例,然后确定应如何表示大小可变的 iterable 或基于时间的迭代;当进度条能够处理该用例而不假定固定长度时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

The problem is this line:
self.total = len(gen) if total is None else total

That is executed at the beginning. But len(gen) might change throughout the iteration, but progress_bar just assumes it keeps still.

What I really want is to use a timer (so "train for 1 hour" instead of "train for so and so epochs").

import time
class Timer:
    def __init__(self, num_seconds):
        self.num_seconds = num_seconds
        self.i = None
        
    def __len__(self):
        if self.i is None: return 1
        eps = 1e-7
        t = time.time() - self.start
        progress = t/num_seconds
        return int((num_seconds*self.i)/(progress+eps)) # estimated size. Changes constantly.
    
    def __iter__(self):
        self.start = time.time()
        self.i, t = 0, 0.0
        while t <= self.num_seconds:
            t = time.time() - self.start
            self.i += 1
            yield None

With this class, if you write

for t in Timer(3.0):
    # do stuff

it runs for 3 seconds. But it doesn't work with the progress_bar :(

主要语言
Jupyter Notebook
星标
1.1k
派生
103
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AnswerDotAI/fastprogress 的其他 Issue

查看 AnswerDotAI/fastprogress 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。