Skip to content

Fix CI starvation: Group heavy pandas tests with interactive subprocess tests - #31077

Closed
sanrishi wants to merge 2 commits into
matplotlib:mainfrom
sanrishi:fix/ci-starvation-grouping
Closed

sanrishi wants to merge 2 commits into
matplotlib:mainfrom
sanrishi:fix/ci-starvation-grouping

Conversation

@sanrishi

@sanrishi sanrishi commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

PR summary

This PR addresses the flaky timeouts observed in the Windows CI environment (and potentially others) where test_backends_interactive.py subprocesses would hang or time out.

Diagnosis

Detailed profiling and discussion (thanks @rcomer and @timhoffm) revealed a Resource Contention issue rather than a simple slow test:

  1. The "Bully": lib/matplotlib/tests/test_axes.py contains pandas-based tests (specifically test_bar_pandas_indexed) that have a heavy setup cost (~2s on a fast local machine, likely 10s+ on CI).

  2. The "Victim": lib/matplotlib/tests/test_backends_interactive.py launches fragile subprocesses that require timely I/O and CPU resources to initialize backends.

  3. The Conflict: When pytest-xdist scheduled these two files on different workers simultaneously, the resource contention caused the subprocesses to starve and eventually time out.

The Fix

Instead of disabling parallelism globally or instrumenting the subprocesses (which is complex), this PR implements a Grouped Isolation Strategy:

  1. Enabled loadgroup: Added --dist loadgroup to azure-pipelines.yml.

  2. Shared Group Tag: Applied @pytest.mark.xdist_group("heavy_resource_group") to both:

    • lib/matplotlib/tests/test_axes.py

    • lib/matplotlib/tests/test_backends_interactive.py

Result: This forces both test modules to run sequentially on the same worker (e.g., both on gw0), ensuring they never execute in parallel. The rest of the test suite remains parallelized.

Verification

Verified locally with python -m pytest -n 2 --dist loadgroup .... Both the heavy pandas tests and the interactive backend tests were assigned to the same worker (gw0), confirming the serialization logic works.

@rcomer: Thanks for the --dist loadgroup pointer; it was the missing piece to enforce the markers.

@timhoffm: I opted for this isolation strategy first as it removes the root cause (contention). If flakes persist, I have a "Plan B" patch ready to add faulthandler instrumentation to the subprocesses to debug the specific hang points.

PR checklist

@timhoffm

timhoffm commented Feb 4, 2026

Copy link
Copy Markdown
Member

Sorry, but as explained in #30851 (comment), the diagnosis stated here is not correct. Therefore, any PR based on that is not a solution.
Please think more carefully before jumping to action.

As mentioned in that post, we do not yet know the root cause, and that means we don’t know the proper fix.

@sanrishi

sanrishi commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

@timhoffm we should take a look on azure ci tests by reruning them after opening the pr again
Rerun will confirm that if timeouts are left or diagnosis worked
Is this diagnosis is good for now ?

@timhoffm

timhoffm commented Feb 5, 2026

Copy link
Copy Markdown
Member

No.

The "Bully": lib/matplotlib/tests/test_axes.py contains pandas-based tests (specifically test_bar_pandas_indexed) that have a heavy setup cost (~2s on a fast local machine, likely 10s+ on CI).

pandas-based tests do not have relevant setup costs.

@sanrishi

sanrishi commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

As mentioned in that post, we do not yet know the root cause, and that means we don’t know the proper fix.

I does as you said by grouping method
Can you please explain chief @timhoffm how we able to know the root cause
So I fix the issue

@timhoffm

timhoffm commented Feb 5, 2026

Copy link
Copy Markdown
Member

Can you please explain chief @timhoffm how we able to know the root cause

😆 That's the art. Analyse the available information, think hard, build a hypothesis, try to verify it, possibly iterate that multiple times until we are convinced we have understood it.

@sanrishi

sanrishi commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

@timhoffm so I should not do anything for now?

@timhoffm

timhoffm commented Feb 5, 2026

Copy link
Copy Markdown
Member

You could do the above stuff if you feel your up to it. We don't have a recipe to tell you do x and y and then it's solved. This is how real problems work 😄.

@sanrishi

sanrishi commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for guidance chief @timhoffm

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Random timeout failures in CI

2 participants