跳转到主要内容

未提供项目描述

项目描述

此库提供了一个简单的接口,用于注册不同的工作负载,并根据当前环境使用纯文本进度条或jupyter小部件来可视化它们的进度。

它可选地依赖于Jupyter小部件,在交互式的Jupyter笔记本环境中绘制漂亮的进度条。

安装

使用pip

pip install progress_reporter

如果您使用IPython/Jupyter,强烈建议您也安装jupyter小部件

pip install ipywidgets

示例

假设您有一个执行一些复杂计算的类,这些计算被分成几个作业/任务/线程等。

为了可视化进度,只需要从progress_reporter.ProgressReporter派生工作类,并调用_progress_register方法来告诉报告者需要完成多少项工作。然后报告者通过调用_progress_update(n)来告诉报告者已经派发了多少项工作。

请注意,这些是“私有”的,用作混合类,而不是污染公共接口。

from progress_reporter import ProgressReporter
import time

class ExampleWorker(ProgressReporter):
    def __init__(self, n_jobs=100):
        self.n_jobs = n_jobs
        """ register the amount of work with the given description """
        self._progress_register(n_jobs, description='Dispatching jobs')

    def work(self):
        """ do some fake work (sleep) and update the progress via the reporter
        """
        for job in (lambda: time.sleep(0.1) for _ in range(self.n_jobs)):
            job()
            # indicate we've finished one job, to update the progress bar
            self._progress_update(1)

它还支持通过设置参数阶段的多阶段顺序工作负载。这只是对底层进程的字典键

class MultiStageWorker(ProgressReporter):
    def __init__(self, n_jobs_init, n_jobs):
        self.n_jobs_init = n_jobs_init
        self.n_jobs = n_jobs
        """ register an expensive initialization routine """
        self._progress_register(self.n_jobs_init, description='initializing', stage=0)
        """ register the main computation """
        self._progress_register(self.n_jobs, description='main computation', stage=1)

    def work(self):
        """ do the initialization """
        for job in (lambda: time.sleep(0.1) for _ in range(self.n_jobs_init)):
            job()
            self._progress_update(1, stage=0)

        """ perform the next stage of the algorithm """
        for job in (lambda: time.sleep(0.2) for _ in range(self.n_jobs)):
            job()
            self._progress_update(1, stage=1)

从2.0版本开始,还有一个适用于组合的此类的版本。

from progress_reporter import ProgressReporter_

class Estimator(object):
    def fit(self, X, y=None):
        pg = ProgressReporter_()
        pg.register(100, description='work')
        with pg.context(): # ensure progress bars are closed if an exception occurs.
            pg.update(50)
            # ...

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

progress-reporter-2.0.tar.gz (49.0 kB 查看哈希值)

上传时间

由以下支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误日志 StatusPageStatusPage 状态页面