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

RuntimeError when call os.remove during os.scandir #1051

Closed
kingronjan opened this issue Aug 20, 2024 · 3 comments · Fixed by #1052
Closed

RuntimeError when call os.remove during os.scandir #1051

kingronjan opened this issue Aug 20, 2024 · 3 comments · Fixed by #1052
Labels

Comments

@kingronjan
Copy link

  • The Operating System
    macos 10.15

  • The Python version
    3.7.5

  • The Module version
    pytest 7.4.0
    pyfakefs 5.5.0

  • A minimal example to reproduce the problem (preferably in the form of a failing test)

import os


def test_file_removed_during_scandir(fs):
    fs.create_file('/wls/1.log')
    fs.create_file('/wls/2.log')
    with os.scandir('/wls') as it:
        for entry in it:
            if entry.is_file():
                os.remove(entry.path)
    assert not os.path.exists('/wls/1.log')
  • The stack trace in case of an unexpected exception.
    File ".../test.py", line 7, in test_file_removed_during_scandir
        for entry in it:
    File ".../pyfakefs/fake_scandir.py", line 149, in __next__
        entry = self.entry_iter.__next__()
RuntimeError: dictionary changed size during iteration

After modified code on fake_scandir.ScanDirIter.__init__ as blow, the test works.

    def __init__(self, filesystem, path):
        ...
        entries = self.filesystem.confirmdir(self.abspath, check_exe_perm=False).entries
        self.entry_iter = iter(list(entries))
@mrbean-bremen
Copy link
Member

Thanks! I will have a look.

@mrbean-bremen
Copy link
Member

@kingronjan - shall be fixed in main now. Will you need a new release?

@kingronjan
Copy link
Author

There is no need for a new release, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants