Skip to content

Commit

Permalink
Use tqdm_class to avoid bug in automatic detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Feb 27, 2022
1 parent bcadcdc commit 91d4a9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
11 changes: 1 addition & 10 deletions flow/project.py
Expand Up @@ -37,16 +37,6 @@
from jinja2 import TemplateNotFound as Jinja2TemplateNotFound
from signac.contrib.filterparse import parse_filter_arg

try:
# If ipywidgets is installed, use "auto" tqdm to improve notebook support.
# Otherwise, use only text-based progress bars. This workaround can be
# removed after https://github.com/tqdm/tqdm/pull/1218.
import ipywidgets # noqa: F401
except ImportError:
from tqdm import tqdm
else:
from tqdm.auto import tqdm

from .aggregates import (
_AggregatesCursor,
_AggregateStore,
Expand Down Expand Up @@ -82,6 +72,7 @@
add_cwd_to_environment_pythonpath,
roundrobin,
switch_to_directory,
tqdm,
)
from .util.translate import abbreviate, shorten

Expand Down
11 changes: 1 addition & 10 deletions flow/render_status.py
Expand Up @@ -2,18 +2,9 @@
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
"""Status rendering logic."""
try:
# If ipywidgets is installed, use "auto" tqdm to improve notebook support.
# Otherwise, use only text-based progress bars. This workaround can be
# removed after https://github.com/tqdm/tqdm/pull/1218.
import ipywidgets # noqa: F401
except ImportError:
from tqdm import tqdm
else:
from tqdm.auto import tqdm

from .scheduling.base import JobStatus
from .util import mistune
from .util.misc import tqdm


def _render_status(
Expand Down
18 changes: 16 additions & 2 deletions flow/util/misc.py
Expand Up @@ -14,6 +14,16 @@
from tqdm.contrib import tmap
from tqdm.contrib.concurrent import process_map, thread_map

try:
# If ipywidgets is installed, use "auto" tqdm to improve notebook support.
# Otherwise, use only text-based progress bars. This workaround can be
# removed after https://github.com/tqdm/tqdm/pull/1218.
import ipywidgets # noqa: F401
except ImportError:
from tqdm import tqdm
else:
from tqdm.auto import tqdm


def _positive_int(value):
"""Parse a command line argument as a positive integer.
Expand Down Expand Up @@ -348,7 +358,10 @@ def _get_parallel_executor(parallelization="none"):
"""
if parallelization == "thread":
parallel_executor = thread_map

def parallel_executor(func, iterable, **kwargs):
return thread_map(func, iterable, tqdm_class=tqdm, **kwargs)

elif parallelization == "process":

def parallel_executor(func, iterable, **kwargs):
Expand All @@ -365,6 +378,7 @@ def parallel_executor(func, iterable, **kwargs):
# regardless of whether it is a local function.
partial(_run_cloudpickled_func, cloudpickle.dumps(func)),
map(cloudpickle.dumps, iterable),
tqdm_class=tqdm,
**kwargs,
)

Expand All @@ -374,6 +388,6 @@ def parallel_executor(func, iterable, **kwargs):
if "chunksize" in kwargs:
# Chunk size only applies to thread/process parallel executors
del kwargs["chunksize"]
return list(tmap(func, iterable, **kwargs))
return list(tmap(func, iterable, tqdm_class=tqdm, **kwargs))

return parallel_executor

0 comments on commit 91d4a9a

Please sign in to comment.