Skip to content

Commit c8ed5ec

Browse files
authored
Release v0.0.4 and add loky as parallel backend. (#4)
1 parent 0d5fffa commit c8ed5ec

18 files changed

+136
-72
lines changed

.conda/meta.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ requirements:
2626
test:
2727
requires:
2828
- pytest
29+
- loky
2930
source_files:
3031
- tox.ini
3132
- tests
@@ -41,4 +42,4 @@ about:
4142
home: https://github.com/pytask-dev/pytask-parallel
4243
license: none
4344
summary: Parallelize the execution of tasks.
44-
dev_url: https://github.com/pytask-dev/pytask-parallel/
45+
dev_url: https://github.com/pytask-dev/pytask-parallel

CHANGES.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ Changes
33

44
This is a record of all past pytask-parallel releases and what went into them in reverse
55
chronological order. Releases follow `semantic versioning <https://semver.org/>`_ and
6-
all releases are available on `Anaconda.org <https://anaconda.org/pytask/pytask-parallel>`_.
6+
all releases are available on `Anaconda.org
7+
<https://anaconda.org/pytask/pytask-parallel>`_.
8+
9+
10+
0.0.4 - 2020-10-30
11+
------------------
12+
13+
- :gh:`4` implement an executor with ``loky``.
714

815

916
0.0.3 - 2020-09-12

README.rst

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,38 @@ pytask-parallel
2121
Parallelize the execution of tasks with `pytask-parallel` which is a plugin for `pytask
2222
<https://github.com/pytask-dev/pytask>`_.
2323

24+
25+
Installation
26+
------------
27+
2428
Install the plugin via ``conda`` with
2529

26-
.. code-block:: bash
30+
.. code-block:: console
2731
2832
$ conda config --add channels conda-forge --add channels pytask
2933
$ conda install pytask-parallel
3034
3135
The plugin uses the ``ProcessPoolExecutor`` or ``ThreadPoolExecutor`` in the
3236
`concurrent.futures <https://docs.python.org/3/library/concurrent.futures.html>`_ module
33-
to execute tasks asynchronously.
37+
to execute tasks asynchronously. By default, processes are used for parallelization.
38+
39+
It is also possible to install ``loky`` with
40+
41+
.. code-block:: console
42+
43+
$ conda install -c conda-forge loky
44+
45+
which is a more robust implementation of the ``ProcessPoolExecutor`` and the default
46+
backend if installed.
47+
48+
49+
Usage
50+
-----
3451

3552
To parallelize your tasks across many workers, pass an integer greater than 1 or
3653
``'auto'`` to the command-line interface.
3754

38-
.. code-block:: bash
55+
.. code-block:: console
3956
4057
$ pytask -n 2
4158
$ pytask --n-workers 2
@@ -44,15 +61,14 @@ To parallelize your tasks across many workers, pass an integer greater than 1 or
4461
$ pytask -n auto
4562
4663
47-
By default, processes are used to parallelize the execution of tasks. This is useful for
48-
CPU bound tasks such as numerical computations. (`Here
49-
<https://stackoverflow.com/a/868577/7523785>`_ is an explanation on what CPU or IO bound
50-
means.)
64+
Using processes to parallelize the execution of tasks is useful for CPU bound tasks such
65+
as numerical computations. (`Here <https://stackoverflow.com/a/868577/7523785>`_ is an
66+
explanation on what CPU or IO bound means.)
5167

5268
For IO bound tasks, tasks where the limiting factor are network responses, accesses to
5369
files, you can parallelize via threads.
5470

55-
.. code-block:: bash
71+
.. code-block:: console
5672
5773
$ pytask --parallel-backend threads
5874
@@ -65,7 +81,7 @@ You can also set the options in one of the configuration files (``pytask.ini``,
6581
6682
[pytask]
6783
n_processes = 1
68-
parallel_backend = processes
84+
parallel_backend = processes # or loky if installed.
6985
7086
7187
Changes

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ dependencies:
1414
# Package dependencies
1515
- pytask >= 0.0.6
1616
- cloudpickle
17+
- loky
1718

1819
# Misc
20+
- black
1921
- bump2version
2022
- jupyterlab
2123
- matplotlib

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.0.3
2+
current_version = 0.0.4
33
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
44
serialize =
55
{major}.{minor}.{patch}dev{dev}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="pytask-parallel",
6-
version="0.0.3",
6+
version="0.0.4",
77
packages=find_packages(where="src"),
88
package_dir={"": "src"},
99
entry_points={"pytask": ["pytask_parallel = pytask_parallel.plugin"]},

src/pytask_parallel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.3"
1+
__version__ = "0.0.4"

src/pytask_parallel/backends.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""This module configures the available backends."""
2+
from concurrent.futures import ProcessPoolExecutor
3+
from concurrent.futures import ThreadPoolExecutor
4+
5+
6+
PARALLEL_BACKENDS = {
7+
"processes": ProcessPoolExecutor,
8+
"threads": ThreadPoolExecutor,
9+
}
10+
11+
PARALLEL_BACKENDS_DEFAULT = "processes"
12+
13+
try:
14+
from loky import get_reusable_executor
15+
16+
PARALLEL_BACKENDS["loky"] = get_reusable_executor
17+
PARALLEL_BACKENDS_DEFAULT = "loky"
18+
except ImportError:
19+
pass

src/pytask_parallel/build.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Extend the build command."""
22
import click
33
from _pytask.config import hookimpl
4+
from pytask_parallel.backends import PARALLEL_BACKENDS
5+
from pytask_parallel.backends import PARALLEL_BACKENDS_DEFAULT
46

57

68
@hookimpl
@@ -18,8 +20,11 @@ def pytask_extend_command_line_interface(cli):
1820
),
1921
click.Option(
2022
["--parallel-backend"],
21-
type=click.Choice(["processes", "threads"]),
22-
help="Backend for the parallelization. [default: processes]",
23+
type=click.Choice(PARALLEL_BACKENDS),
24+
help=(
25+
"Backend for the parallelization. "
26+
f"[default: {PARALLEL_BACKENDS_DEFAULT}]"
27+
),
2328
default=None,
2429
),
2530
click.Option(

src/pytask_parallel/callbacks.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Validate command line inputs and configuration values."""
2+
from pytask_parallel.backends import PARALLEL_BACKENDS
23

34

45
def n_workers_callback(value):
56
"""Validate the n-workers option."""
67
if value == "auto":
78
pass
8-
elif value is None or value == "None":
9+
elif value in [None, "None", "none"]:
910
value = None
1011
elif isinstance(value, int) and 1 <= value:
1112
pass
@@ -19,16 +20,20 @@ def n_workers_callback(value):
1920

2021
def parallel_backend_callback(value):
2122
"""Validate the input for the parallel backend."""
22-
if value == "None":
23+
if value in [None, "None", "none"]:
2324
value = None
24-
if value not in ["processes", "threads", None]:
25-
raise ValueError("parallel_backend has to be 'processes' or 'threads'.")
25+
elif value in PARALLEL_BACKENDS:
26+
pass
27+
else:
28+
raise ValueError(
29+
f"parallel_backend has to be one of {list(PARALLEL_BACKENDS)}."
30+
)
2631
return value
2732

2833

2934
def delay_callback(value):
3035
"""Validate the delay option."""
31-
if value is None or value == "None":
36+
if value in [None, "None", "none"]:
3237
value = None
3338
else:
3439
try:

0 commit comments

Comments
 (0)