当前位置: 首页>>代码示例>>Python>>正文


Python progressbar.ProgressBar方法代码示例

本文整理汇总了Python中progressbar.ProgressBar方法的典型用法代码示例。如果您正苦于以下问题:Python progressbar.ProgressBar方法的具体用法?Python progressbar.ProgressBar怎么用?Python progressbar.ProgressBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在progressbar的用法示例。


在下文中一共展示了progressbar.ProgressBar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_to_file

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def download_to_file(path, ext):
    # Is it worth to have the same name?
    # ppath = urlparse(path).path.split("/")
    # ppath = ppath[-1] if len(ppath) > 0 else None
    _, file_name = tempfile.mkstemp("." + ext)
    r = requests.get(path, stream=True)
    total_length = r.headers.get('content-length')
    dl = 0
    with open(file_name, 'wb') as f:
        if total_length is None:
            f.write(r.content)
        else:
            total_length = int(total_length)
            pbar = ProgressBar(maxval=total_length).start()
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:  # filter out keep-alive new chunks
                    pbar.update(dl * len(chunk))
                    dl += 1
                    f.write(chunk)
                    f.flush()
            pbar.finish()
    return file_name 
开发者ID:rockneurotiko,项目名称:pybotgram,代码行数:24,代码来源:utils.py

示例2: show_progress

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def show_progress(block_num, block_size, total_size):
    global pbar

    if pbar is None:
        if total_size > 0:
            prefixes = ('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi')
            power = min(int(math.log(total_size, 2) / 10), len(prefixes) - 1)
            scaled = float(total_size) / (2 ** (10 * power))
            total_size_str = '{:.1f} {}B'.format(scaled, prefixes[power])
            try:
                marker = '█'
            except UnicodeEncodeError:
                marker = '*'
            widgets = [
                progressbar.Percentage(),
                ' ', progressbar.DataSize(),
                ' / ', total_size_str,
                ' ', progressbar.Bar(marker=marker),
                ' ', progressbar.ETA(),
                ' ', progressbar.AdaptiveTransferSpeed(),
            ]
            pbar = progressbar.ProgressBar(widgets=widgets,
                                           max_value=total_size)
        else:
            widgets = [
                progressbar.DataSize(),
                ' ', progressbar.Bar(marker=progressbar.RotatingMarker()),
                ' ', progressbar.Timer(),
                ' ', progressbar.AdaptiveTransferSpeed(),
            ]
            pbar = progressbar.ProgressBar(widgets=widgets,
                                           max_value=progressbar.UnknownLength)

    downloaded = block_num * block_size
    if downloaded < total_size:
        pbar.update(downloaded)
    else:
        pbar.finish()
        pbar = None 
开发者ID:thu-ml,项目名称:zhusuan,代码行数:41,代码来源:dataset.py

示例3: __init__

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def __init__(self, n_epochs, train_size, valid_size):
        self.n_epochs = n_epochs
        self.train_size = train_size
        self.valid_size = valid_size
        self.t = Terminal()
        s = 10
        e = 1   # epoch bar position
        tr = 3  # train bar position
        ts = 6  # valid bar position
        h = self.t.height

        for i in range(10):
            print('')
        self.epoch_bar = progressbar.ProgressBar(max_value=n_epochs, fd=Writer(self.t, (0, h-s+e)))

        self.train_writer = Writer(self.t, (0, h-s+tr))
        self.train_bar_writer = Writer(self.t, (0, h-s+tr+1))

        self.valid_writer = Writer(self.t, (0, h-s+ts))
        self.valid_bar_writer = Writer(self.t, (0, h-s+ts+1))

        self.reset_train_bar()
        self.reset_valid_bar() 
开发者ID:ClementPinard,项目名称:SfmLearner-Pytorch,代码行数:25,代码来源:logger.py

示例4: load_data

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def load_data(self):
        page_no = 1
        df_list = []
        df, msg, pageinfo = self._get_fund_list_page(page_no)
        if df is None:
            return None, msg

        df_list.append(df)
        page_count = pageinfo['pagecount']
        process_bar = ProgressBar().start(max_value=page_count)

        page_no = page_no + 1
        while page_no <= page_count:
            df, msg, pageinfo = self._get_fund_list_page(page_no)
            if df is None:
                return None, msg
            df_list.append(df)
            process_bar.update(page_no)
            page_no = page_no + 1

        self.df_fundlist = pd.concat(df_list)
        return self.df_fundlist, '' 
开发者ID:PKUJohnson,项目名称:OpenData,代码行数:24,代码来源:simu_agent.py

示例5: get_fund_list

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def get_fund_list(self):
        df_company, msg = self.get_fund_company()
        if df_company is None:
            return None, msg

        df_result = []
        process_bar = ProgressBar().start(max_value=len(df_company))
        for index, row in df_company.iterrows():
            companyid   = row['companyid']
            companyname = row['companyname']

            df, msg = self.get_fundlist_by_company(companyid)
            if df is not None:
                df['companyname'] = companyname
                df['companyid']   = companyid
                df_result.append(df)

            process_bar.update(index+1)

        return pd.concat(df_result), '' 
开发者ID:PKUJohnson,项目名称:OpenData,代码行数:22,代码来源:fund_agent.py

示例6: reset

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def reset(self, mode, make_pbar=True, string=''):
        self.mode = mode
        self.u = 0

        if make_pbar:
            widgets = [string, Timer(), ' | ',
                       Percentage(), ' | ', ETA(), Bar()]
            if len([len(loader[self.mode]) for loader
                    in self.loaders.values()]) == 0:
                maxval = 1000
            else:
                maxval = min(len(loader[self.mode])
                             for loader in self.loaders.values())
            self.pbar = ProgressBar(widgets=widgets, maxval=maxval).start()
        else:
            self.pbar = None

        sources = self.loaders.keys()
        self.iterators = dict((source, self.make_iterator(source))
                              for source in sources) 
开发者ID:rdevon,项目名称:cortex,代码行数:22,代码来源:data_handler.py

示例7: test_progress

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def test_progress():
    mem = Memory('app01.example.com', 1073741824, progressbar=True)
    mem.bar = ProgressBar(widgets=mem.widgets,
                          maxval=mem.max_size).start()
    mem.transfered = 536870912
    mem.update_progress()
    mem.transfered = 2147483648
    mem.update_progress()
    mem.update_progress(complete=True)

    mem = Memory('app02.example.com', 1073741824, progressbar=False)
    mem.bar = ProgressBar(widgets=mem.widgets,
                          maxval=mem.max_size).start()
    mem.transfered = 536870912
    mem.update_progress()
    mem.transfered = 2147483648
    mem.update_progress()
    mem.update_progress(complete=True) 
开发者ID:ThreatResponse,项目名称:margaritashotgun,代码行数:20,代码来源:test_memory.py

示例8: killProcTree

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def killProcTree(pid=None, including_parent=True):
    if not pid:
        # kill the process itself
        pid = os.getpid()
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    for child in children:
        child.kill()
    psutil.wait_procs(children, timeout=5)
    if including_parent:
        parent.kill()
        parent.wait(5)


###########################################################
# ProgressBar
########################################################### 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:19,代码来源:job_util.py

示例9: do_import_licenses

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def do_import_licenses(file_data: List[dict]):
    imported = set()
    print("Importing licenses ... ", flush=True)
    with progressbar.ProgressBar(max_value=len(file_data)) as bar:
        for idx, p in enumerate(file_data):
            info = p.get('info')
            license_text = detect_license(info.get('license'))

            if license_text and license_text not in imported:
                imported.add(license_text)
                session: Session = DbSession.factory()

                package_license = License()
                package_license.id = license_text
                package_license.description = info.get('license')

                session.add(package_license)
                session.commit()

            bar.update(idx)

    sys.stderr.flush()
    sys.stdout.flush() 
开发者ID:talkpython,项目名称:data-driven-web-apps-with-pyramid-and-sqlalchemy,代码行数:25,代码来源:load_data.py

示例10: do_user_import

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def do_user_import(user_lookup: Dict[str, str]) -> Dict[str, User]:
    print("Importing users ... ", flush=True)
    with progressbar.ProgressBar(max_value=len(user_lookup)) as bar:
        for idx, (email, name) in enumerate(user_lookup.items()):
            session: Session = DbSession.factory()
            session.expire_on_commit = False

            user = User()
            user.email = email
            user.name = name
            session.add(user)

            session.commit()
            bar.update(idx)

    print()
    sys.stderr.flush()
    sys.stdout.flush()

    session: Session = DbSession.factory()
    return {u.email: u for u in session.query(User)} 
开发者ID:talkpython,项目名称:data-driven-web-apps-with-pyramid-and-sqlalchemy,代码行数:23,代码来源:load_data.py

示例11: do_import_packages

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def do_import_packages(file_data: List[dict], user_lookup: Dict[str, User]):
    errored_packages = []
    print("Importing packages and releases ... ", flush=True)
    with progressbar.ProgressBar(max_value=len(file_data)) as bar:
        for idx, p in enumerate(file_data):
            try:
                load_package(p, user_lookup)
                bar.update(idx)
            except Exception as x:
                errored_packages.append((p, " *** Errored out for package {}, {}".format(p.get('package_name'), x)))
                raise
    sys.stderr.flush()
    sys.stdout.flush()
    print()
    print("Completed packages with {} errors.".format(len(errored_packages)))
    for (p, txt) in errored_packages:
        print(txt) 
开发者ID:talkpython,项目名称:data-driven-web-apps-with-pyramid-and-sqlalchemy,代码行数:19,代码来源:load_data.py

示例12: do_load_files

# 需要导入模块: import progressbar [as 别名]
# 或者: from progressbar import ProgressBar [as 别名]
def do_load_files() -> List[dict]:
    data_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../../../data/pypi-top-100'))
    print("Loading files from {}".format(data_path))
    files = get_file_names(data_path)
    print("Found {:,} files, loading ...".format(len(files)), flush=True)
    time.sleep(.1)

    file_data = []
    with progressbar.ProgressBar(max_value=len(files)) as bar:
        for idx, f in enumerate(files):
            file_data.append(load_file_data(f))
            bar.update(idx)

    sys.stderr.flush()
    sys.stdout.flush()
    print()
    return file_data 
开发者ID:talkpython,项目名称:data-driven-web-apps-with-pyramid-and-sqlalchemy,代码行数:19,代码来源:load_data.py


注:本文中的progressbar.ProgressBar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。