Skip to content

Commit d78d0ea

Browse files
committed
Use maximum cores for jobs=0
Fixes #207
1 parent cbf8bfd commit d78d0ea

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

docs/src/markdown/about/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.12
4+
5+
- **NEW**: When `jobs` is set to `0`, use maximum available cores.
6+
37
## 2.11
48

59
- **NEW**: Add new command line option `--skip-dict-compile` which will skip the dictionary compiling step if the

docs/src/markdown/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ process files in a given task.
1919
jobs: 4
2020
```
2121

22+
If `jobs` is set to `0`, the maximum available cores will be used.
23+
2224
/// new | New 2.10
2325
Parallel processing is new in 2.10.
2426
///

pyspelling/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class SpellingTask:
578578
"O": glob.O
579579
}
580580

581-
def __init__(self, checker, config, binary='', verbose=0, jobs=0, debug=False, skip_dict_compile=False):
581+
def __init__(self, checker, config, binary='', verbose=0, jobs=None, debug=False, skip_dict_compile=False):
582582
"""Initialize."""
583583

584584
if checker == "hunspell": # pragma: no cover
@@ -678,12 +678,14 @@ def run_task(self, task, source_patterns=None):
678678
source_patterns = self.task.get('sources', [])
679679

680680
# If jobs was not specified via command line, check the config for jobs settings
681-
jobs = max(1, self.config.get('jobs', 1) if self.jobs == 0 else self.jobs)
681+
jobs = self.config.get('jobs', 1) if self.jobs is None else self.jobs
682+
if jobs < 0:
683+
jobs = 1
682684

683685
expect_match = self.task.get('expect_match', True)
684-
if jobs > 1:
686+
if jobs != 1:
685687
# Use multi-processing to process files concurrently
686-
with ProcessPoolExecutor(max_workers=jobs) as pool:
688+
with ProcessPoolExecutor(max_workers=jobs if jobs else None) as pool:
687689
for results in pool.map(self.multi_check, self.walk_src(source_patterns, glob_flags, glob_limit)):
688690
self.found_match = True
689691
yield from results
@@ -711,7 +713,7 @@ def spellcheck(
711713
sources=None,
712714
verbose=0,
713715
debug=False,
714-
jobs=0,
716+
jobs=None,
715717
skip_dict_compile=False
716718
):
717719
"""Spell check."""

pyspelling/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main():
2020
'--jobs', '-j',
2121
action='store',
2222
type=int,
23-
default=0,
23+
default=None,
2424
help="Specify the number of spell checker processes to run in parallel."
2525
)
2626
parser.add_argument('--config', '-c', action='store', default='', help="Spelling config.")
@@ -64,7 +64,9 @@ def run(config, **kwargs):
6464
verbose = kwargs.get('verbose', 0)
6565
sources = kwargs.get('sources', [])
6666
debug = kwargs.get('debug', False)
67-
jobs = kwargs.get('jobs', 0)
67+
jobs = kwargs.get('jobs', None)
68+
if jobs is not None and jobs < 0:
69+
jobs = 1
6870
skip_dict_compile = kwargs.get('skip_dict_compile', False)
6971

7072
fail = False

pyspelling/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,5 @@ def parse_version(ver):
188188
return Version(major, minor, micro, release, pre, post, dev)
189189

190190

191-
__version_info__ = Version(2, 11, 0, "final")
191+
__version_info__ = Version(2, 12, 0, "final")
192192
__version__ = __version_info__._get_canonical()

0 commit comments

Comments
 (0)