Skip to content

Commit 732f75a

Browse files
committed
No initiate _progress at here. Let it handle outside
1 parent 2256943 commit 732f75a

2 files changed

Lines changed: 55 additions & 58 deletions

File tree

baidupcs_py/commands/download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from baidupcs_py.common import constant
1414
from baidupcs_py.common.io import to_decryptio, DecryptIO, READ_SIZE, MAX_CHUNK_SIZE
1515
from baidupcs_py.common.downloader import MeDownloader
16-
from baidupcs_py.common.progress_bar import _progress, progress_task_exists
16+
from baidupcs_py.common.progress_bar import (
17+
_progress,
18+
init_progress_bar,
19+
progress_task_exists,
20+
)
1721
from baidupcs_py.commands.sifter import Sifter, sift
1822
from baidupcs_py.commands.log import get_logger
1923
from baidupcs_py.commands.display import display_blocked_remotepath
@@ -143,8 +147,7 @@ def _me_download(
143147

144148
task_id: Optional[TaskID] = None
145149
if not downloadparams.quiet:
146-
if not _progress.live._started:
147-
_progress.start()
150+
init_progress_bar()
148151
task_id = _progress.add_task("MeDownloader", start=False, title=localpath)
149152

150153
def _wrap_done_callback(fut: Future):

baidupcs_py/commands/upload.py

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,24 @@ def upload_one_by_one(
339339
):
340340
"""Upload files one by one with uploading the slices concurrently"""
341341

342-
with _progress:
343-
for from_to in from_to_list:
344-
task_id = None
345-
if show_progress:
346-
task_id = _progress.add_task("upload", start=False, title=from_to.from_)
347-
upload_file_concurrently(
348-
api,
349-
from_to,
350-
ondup,
351-
max_workers=max_workers,
352-
encrypt_password=encrypt_password,
353-
encrypt_type=encrypt_type,
354-
slice_size=slice_size,
355-
ignore_existing=ignore_existing,
356-
task_id=task_id,
357-
user_id=user_id,
358-
user_name=user_name,
359-
check_md5=check_md5,
360-
)
342+
for from_to in from_to_list:
343+
task_id = None
344+
if show_progress:
345+
task_id = _progress.add_task("upload", start=False, title=from_to.from_)
346+
upload_file_concurrently(
347+
api,
348+
from_to,
349+
ondup,
350+
max_workers=max_workers,
351+
encrypt_password=encrypt_password,
352+
encrypt_type=encrypt_type,
353+
slice_size=slice_size,
354+
ignore_existing=ignore_existing,
355+
task_id=task_id,
356+
user_id=user_id,
357+
user_name=user_name,
358+
check_md5=check_md5,
359+
)
361360

362361
logger.debug("======== Uploading end ========")
363362

@@ -570,44 +569,39 @@ def upload_many(
570569

571570
excepts = {}
572571
semaphore = Semaphore(max_workers)
573-
with _progress:
574-
with ThreadPoolExecutor(max_workers=max_workers) as executor:
575-
futs = {}
576-
for idx, from_to in enumerate(from_to_list):
577-
semaphore.acquire()
578-
task_id = None
579-
if show_progress:
580-
task_id = _progress.add_task(
581-
"upload", start=False, title=from_to.from_
582-
)
583-
584-
logger.debug(
585-
"`upload_many`: Upload: index: %s, task_id: %s", idx, task_id
586-
)
572+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
573+
futs = {}
574+
for idx, from_to in enumerate(from_to_list):
575+
semaphore.acquire()
576+
task_id = None
577+
if show_progress:
578+
task_id = _progress.add_task("upload", start=False, title=from_to.from_)
587579

588-
fut = executor.submit(
589-
sure_release,
590-
semaphore,
591-
upload_file,
592-
api,
593-
from_to,
594-
ondup,
595-
encrypt_password=encrypt_password,
596-
encrypt_type=encrypt_type,
597-
slice_size=slice_size,
598-
ignore_existing=ignore_existing,
599-
task_id=task_id,
600-
user_id=user_id,
601-
user_name=user_name,
602-
check_md5=check_md5,
603-
)
604-
futs[fut] = from_to
580+
logger.debug("`upload_many`: Upload: index: %s, task_id: %s", idx, task_id)
581+
582+
fut = executor.submit(
583+
sure_release,
584+
semaphore,
585+
upload_file,
586+
api,
587+
from_to,
588+
ondup,
589+
encrypt_password=encrypt_password,
590+
encrypt_type=encrypt_type,
591+
slice_size=slice_size,
592+
ignore_existing=ignore_existing,
593+
task_id=task_id,
594+
user_id=user_id,
595+
user_name=user_name,
596+
check_md5=check_md5,
597+
)
598+
futs[fut] = from_to
605599

606-
for fut in as_completed(futs):
607-
e = fut.exception()
608-
if e is not None:
609-
from_to = futs[fut]
610-
excepts[from_to] = e
600+
for fut in as_completed(futs):
601+
e = fut.exception()
602+
if e is not None:
603+
from_to = futs[fut]
604+
excepts[from_to] = e
611605

612606
logger.debug("======== Uploading end ========")
613607

0 commit comments

Comments
 (0)