Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit CPU number on Windows #159

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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