當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。