Skip to content

Commit b867c28

Browse files
authored
Implement a none backend as default. (#94)
1 parent 821ee83 commit b867c28

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/pytask_parallel/backends.py

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def _get_thread_pool_executor(n_workers: int) -> Executor:
8484
class ParallelBackend(Enum):
8585
"""Choices for parallel backends."""
8686

87+
NONE = "none"
88+
8789
CUSTOM = "custom"
8890
DASK = "dask"
8991
LOKY = "loky"

src/pytask_parallel/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
2626
["--parallel-backend"],
2727
type=EnumChoice(ParallelBackend),
2828
help="Backend for the parallelization.",
29-
default=ParallelBackend.LOKY,
29+
default=ParallelBackend.NONE,
3030
),
3131
]
3232
cli.commands["build"].params.extend(additional_parameters)

src/pytask_parallel/config.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
2121
"""Parse the configuration."""
2222
__tracebackhide__ = True
2323

24-
if config["n_workers"] == "auto":
25-
config["n_workers"] = max(os.cpu_count() - 1, 1)
26-
2724
try:
2825
config["parallel_backend"] = ParallelBackend(config["parallel_backend"])
2926
except ValueError:
@@ -33,6 +30,13 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
3330
)
3431
raise ValueError(msg) from None
3532

33+
if config["n_workers"] == "auto":
34+
config["n_workers"] = max(os.cpu_count() - 1, 1)
35+
36+
# If more than one worker is used, and no backend is set, use loky.
37+
if config["n_workers"] > 1 and config["parallel_backend"] == ParallelBackend.NONE:
38+
config["parallel_backend"] = ParallelBackend.LOKY
39+
3640
config["delay"] = 0.1
3741

3842

@@ -43,6 +47,9 @@ def pytask_post_parse(config: dict[str, Any]) -> None:
4347
if config["pdb"] or config["trace"] or config["dry_run"]:
4448
return
4549

50+
if config["parallel_backend"] == ParallelBackend.NONE:
51+
return
52+
4653
# Register parallel execute and logging hook.
4754
config["pm"].register(logging)
4855
config["pm"].register(execute)

0 commit comments

Comments
 (0)