Skip to content

fix: set fixed paths_list in TreeMatcher init#2130

Merged
nedbat merged 1 commit intocoveragepy:mainfrom
colorlace:set-paths
Feb 7, 2026
Merged

fix: set fixed paths_list in TreeMatcher init#2130
nedbat merged 1 commit intocoveragepy:mainfrom
colorlace:set-paths

Conversation

@colorlace
Copy link
Contributor

This lil fix simply ensures we don't get hit with RuntimeError: Set changed size during iteration if there's any concurrent update to sys.paths while TreeMatcher.__init__ runs.

My CI pipeline has encountered this error:

.venv/lib/python3.11/site-packages/coverage/inorout.py:354: in should_trace
    self.set_matchers_depending_on_syspath()
.venv/lib/python3.11/site-packages/coverage/inorout.py:308: in set_matchers_depending_on_syspath 
    self.third_match = TreeMatcher(self.third_paths, "third", "Third-party lib", self._debug)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.11/site-packages/coverage/files.py:266: in __init_
    for p in paths: 
E     RuntimeError: Set changed size during iteration

This seems like a very similar situation to #1733
which was fixed by something similar: 08fc997.

@nedbat
Copy link
Member

nedbat commented Feb 7, 2026

Thanks for this. Can you share the project that caused the error? I'd like to understand better where the concurrent access is coming from.

@colorlace
Copy link
Contributor Author

colorlace commented Feb 7, 2026

Thanks for this. Can you share the project that caused the error? I'd like to understand better where the concurrent access is coming from.

Unfortunately it's a closed-source company project. But I believe it occurs because, during testing, we run

from pyspark.sql import SparkSession

which updates the sys.path. I suppose this happens concurrently while coveragepy is doin its thang.

@nedbat
Copy link
Member

nedbat commented Feb 7, 2026

It looks like a good fix, thanks.

@nedbat nedbat merged commit 371fcc5 into coveragepy:main Feb 7, 2026
79 of 80 checks passed
@colorlace
Copy link
Contributor Author

Thanks Ned you're a legend! (Unicode sandwich saved me ten years ago when I started coding)

@nedbat
Copy link
Member

nedbat commented Feb 7, 2026

Wow, Unicode sandwich, a historical deep cut! :D

@colorlace
Copy link
Contributor Author

Haha I did a double take when I saw your name on the contributors list. Definitely uncovered some old memories of string processing pain (and retribution) XD

@nedbat
Copy link
Member

nedbat commented Feb 9, 2026

This is now released as part of coverage 7.13.4.

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.

2 participants