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

Crashes with RuntimeError: dictionary changed size during iteration #3097

Open
andreyryabtsev opened this issue Jan 28, 2025 · 0 comments
Open

Comments

@andreyryabtsev
Copy link

andreyryabtsev commented Jan 28, 2025

Check the bug
Before filling this bug report, please search if a similar issue already exists.
In this case, just add a comment on this existing issue.

#3091 mentions the same crash, but is not primarily about it.

Describe the bug
A clear and concise description of what the bug is.

After running fine for some hours, Glances consistently crashes with the following stack trace:

  File "C:\Users\ryabtsev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\glances\processes.py", line 628, in update_list
    return list_of_namedtuple_to_list_of_dict(processlist)
  File "C:\Users\ryabtsev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\glances\globals.py", line 495, in list_of_namedtuple_to_list_of_dict
    return [namedtuple_to_dict(d) for d in data]
            ^^^^^^^^^^^^^^^^^^^^^
  File "/app/glances/globals.py", line 490, in namedtuple_to_dict
    return {k: (v._asdict() if hasattr(v, '_asdict') else v) for k, v in data.items()}
                                                                         ^^^^^^^^^^^^
RuntimeError: dictionary changed size during iteration

To Reproduce
Steps to reproduce the behavior:

  1. Start Glances with the following options '-w'
  2. Wait X hours (X < 24)
  3. See error

Expected behavior
Glances doesn't hit multithreading errors

Screenshots
N/A

Environement (please complete the following information)

  • Operating System (lsb_release -a or OS name/version): Windows 11 Pro 64-bit Build 26100
  • Glances & psutil versions: Glances version: 4.3.0.8 | Glances API version: 4 | PsUtil version: 6.1.1
  • How do you install Glances (Pypi package, script, package manager, source): Pypi
  • Glances test: .../glances.exe --issue: https://pastebin.com/nPPcG8x0

Additional context
Should a threading.Lock be used on these globals (https://docs.python.org/3/library/threading.html#lock-objects)? Alternatively, storing .keys() and accessing them with handling for when they are removed by another thread during iteration.
I have no idea if this works as intended but i.e.:

keys = list(data.keys())  # grab keys atomically 
output = {}
for key in keys:
  value = data.get(key, None)
  if value is None:
    continue
  if hasattr(value, '_asdict'):
    value = value._asdict()
  output[key] = value
return output

You can also pastebin:

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

No branches or pull requests

2 participants