Skip to content

Run CI tests with max processes#7254

Open
ShaharNaveh wants to merge 3 commits intoRustPython:mainfrom
ShaharNaveh:parallel-ci
Open

Run CI tests with max processes#7254
ShaharNaveh wants to merge 3 commits intoRustPython:mainfrom
ShaharNaveh:parallel-ci

Conversation

@ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Feb 27, 2026

Recently our CI has started to take around an hour, this will make it faster at the cost of stability. I want to see how faster / stable this effect the CI

Summary by CodeRabbit

  • Chores
    • Updated CI/CD workflow to optimize test execution logic and handle multiprocessing tests separately.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

The CI workflow now separates handling of flaky multiprocessing tests from regular tests. It introduces core detection to enable parallel test execution, runs flaky MP tests with a single core initially, and then runs standard tests with detected cores while skipping flaky tests.

Changes

Cohort / File(s) Summary
CI Test Execution Restructuring
.github/workflows/ci.yaml
Replaces PLATFORM_INDEPENDENT_TESTS with FLAKY_MP_TESTS list, adds a step to detect available cores for dynamic parallelization, and separates CPython test execution into two phases: flaky multiprocessing tests with single-core execution and standard tests with multi-core execution while excluding flaky tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 The tests now run with cores galore,

Flaky ones get a single door,

While others hop in parallel might,

The workflow bounds with more delight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Run CI tests with max processes' is directly related to the main changeset objective of running tests with maximum processes to reduce CI runtime, and clearly summarizes the primary change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ShaharNaveh ShaharNaveh changed the title Run CI tests with 4 processes Run CI tests with max processes Mar 1, 2026
test_unpack_ex
test_weakref
test_yield_from
# Tests that can be flaky when running with multiple processes `-j 2`. These tests will be ran using `-j 1`
Copy link
Contributor Author

@ShaharNaveh ShaharNaveh Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowone can you please let me know what you think about this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how is this different from marking those tests with, say, @support.thread_unsafe("TODO: RUSTPYTHON, blah blah blah...")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how is this different from marking those tests with, say, @support.thread_unsafe("TODO: RUSTPYTHON, blah blah blah...")?

That's a good point. If this is the approach we are gonna choose then we need to add support for lib_updater for it as well, ATM it only looks at unittest patches

@youknowone
Copy link
Member

Whats the option cpython is using?

@ShaharNaveh
Copy link
Contributor Author

ShaharNaveh commented Mar 18, 2026

Whats the option cpython is using?

CPython uses max processes for their CI (from what I can tell)

@ShaharNaveh ShaharNaveh marked this pull request as ready for review March 18, 2026 13:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/ci.yaml:
- Around line 243-249: The "Detect available cores" step is calling a
non-existent Python function os.process_cpu_count(); update the step (id: cores)
to avoid Python and use bash instead: detect CPU count with a POSIX-safe command
such as nproc or getconf _NPROCESSORS_ONLN (falling back to 2 if detection
fails), assign the result to the cores variable and then echo "cores=${cores}"
>> $GITHUB_OUTPUT; ensure the step retains shell: bash and preserves the output
key name and id (cores) so downstream jobs still read the value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 23cc4bdc-425b-4286-9c21-25706e3ebe20

📥 Commits

Reviewing files that changed from the base of the PR and between 3148024 and ccb66b1.

📒 Files selected for processing (1)
  • .github/workflows/ci.yaml

Comment on lines +243 to +249
- name: Detect available cores
id: cores
shell: bash
run: |
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed --timeout 600 -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
timeout-minutes: 45
cores=$(python -c 'print(__import__("os").process_cpu_count())')
echo "cores=${cores}" >> $GITHUB_OUTPUT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

In Python 3.14, can os.process_cpu_count() return None, and is a fallback required before using it as an integer worker count?

💡 Result:

No, os.process_cpu_count does not exist in Python 3.14, and thus cannot return None. The standard function is os.cpu_count, which returns the number of logical CPUs in the system or None if indeterminable. A fallback (e.g., defaulting to 1 or 4) is required when using it as an integer worker count, such as in multiprocessing.Pool(processes=os.cpu_count).

Citations:


🏁 Script executed:

# Check the actual content of lines 243-249 in .github/workflows/ci.yaml
head -n 249 .github/workflows/ci.yaml | tail -n 7

Repository: RustPython/RustPython

Length of output: 280


Fix non-existent function call in core detection.

Line 247 calls os.process_cpu_count(), which does not exist in Python—the correct function is os.cpu_count(), which can also return None. This will cause runtime failure. Additionally, Python for CI test orchestration introduces unnecessary complexity; use bash directly with fallbacks.

🛠️ Suggested fix
       - name: Detect available cores
         id: cores
         shell: bash
         run: |
-          cores=$(python -c 'print(__import__("os").process_cpu_count())')
-          echo "cores=${cores}" >> $GITHUB_OUTPUT
+          cores="${NUMBER_OF_PROCESSORS:-}"
+          if [ -z "${cores}" ]; then
+            cores="$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 1)"
+          fi
+          echo "cores=${cores}" >> "$GITHUB_OUTPUT"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Detect available cores
id: cores
shell: bash
run: |
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed --timeout 600 -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
timeout-minutes: 45
cores=$(python -c 'print(__import__("os").process_cpu_count())')
echo "cores=${cores}" >> $GITHUB_OUTPUT
- name: Detect available cores
id: cores
shell: bash
run: |
cores="${NUMBER_OF_PROCESSORS:-}"
if [ -z "${cores}" ]; then
cores="$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 1)"
fi
echo "cores=${cores}" >> "$GITHUB_OUTPUT"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yaml around lines 243 - 249, The "Detect available
cores" step is calling a non-existent Python function os.process_cpu_count();
update the step (id: cores) to avoid Python and use bash instead: detect CPU
count with a POSIX-safe command such as nproc or getconf _NPROCESSORS_ONLN
(falling back to 2 if detection fails), assign the result to the cores variable
and then echo "cores=${cores}" >> $GITHUB_OUTPUT; ensure the step retains shell:
bash and preserves the output key name and id (cores) so downstream jobs still
read the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants