Skip to content

Commit

Permalink
Limit CPU number on Windows (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Mar 29, 2024
1 parent 0a9fbe5 commit d959573
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bump_pydantic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools
import multiprocessing
import os
import platform
import time
import traceback
from collections import deque
Expand Down Expand Up @@ -31,6 +32,11 @@

DEFAULT_IGNORES = [".venv/**", ".tox/**"]

processes = os.cpu_count()
# Windows has a limit of 61 processes. See https://github.com/python/cpython/issues/89240.
if platform.system() == "Windows" and processes is not None:
processes = min(processes, 61)


def version_callback(value: bool):
if value:
Expand Down Expand Up @@ -126,7 +132,7 @@ def main(
task = progress.add_task(description="Executing codemods...", total=len(files))
count_errors = 0
difflines: List[List[str]] = []
with multiprocessing.Pool() as pool:
with multiprocessing.Pool(processes=processes) as pool:
for error, _difflines in pool.imap_unordered(partial_run_codemods, files):
progress.advance(task)

Expand Down

0 comments on commit d959573

Please sign in to comment.