Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#22017 closed Bug (fixed)

RuntimeError: dictionary changed size during iteration

Reported by: quinox Owned by: nobody
Component: Python 3 Version: 1.7-alpha-1
Severity: Normal Keywords:
Cc:… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


This bug report is identical to #21049 but for Django 1.7.

I run Django 1.7a2 with a Python3 virtualenv. Occasionally the runserver crashes with the following stacktrace:

System check identified no issues (0 silenced).
Traceback (most recent call last):
  File "", line 10, in <module>
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/", line 427, in execute_from_command_line
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/", line 419, in execute
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/", line 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/", line 336, in execute
    output = self.handle(*args, **options)
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/commands/", line 81, in handle*args, **options)
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/core/management/commands/", line 90, in run
    autoreload.main(self.inner_run, args, options)
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 267, in main
    reloader(wrapped_main_func, args, kwargs)
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 233, in python_reloader
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 212, in reloader_thread
    if fn():
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 139, in inotify_code_changed
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 132, in update_watch
    for path in gen_filenames():
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 84, in gen_filenames
    filenames = [filename.__file__ for filename in sys.modules.values()
  File "/home/quinox/projecten/deadlines/virtual/lib/python3.3/site-packages/django/utils/", line 84, in <listcomp>
    filenames = [filename.__file__ for filename in sys.modules.values()
RuntimeError: dictionary changed size during iteration

The issue shows up sporadically, it can usually be triggered within 10 minutes by running the following command in a shell:

while true ; do touch project/xxx/ ; sleep 1s; done

The fix as suggested in #21049 seems to fix the issue, I haven't seen the runserver crash since I modified django/utils/ lines 84-85 from:

filenames = [filename.__file__ for filename in sys.modules.values()
            if hasattr(filename, '__file__')]


filenames = [filename.__file__ for filename in list(sys.modules.values())
            if hasattr(filename, '__file__')]

Change History (4)

comment:1 Changed 5 years ago by quinox

Cc:… added
Component: UncategorizedPython 3
Type: UncategorizedBug

comment:2 Changed 5 years ago by Claude Paroz

Easy pickings: set
Triage Stage: UnreviewedAccepted

Regression was introduced in 15f82c701161b327cef54b469c00b6cbe01534db.

comment:3 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In e0381cdf2e7f677c5b29f2e3351993e92915569a:

Fixed #22017 -- Prevented RuntimeError on Python 3

Refs #21049. Thanks quinox for the report.

comment:4 Changed 5 years ago by Alex Gaynor <alex.gaynor@…>

In 608e6eb2959c6e56e5c702ca0d15fa0e6c2eef16:

Added an explanatory comment. Refs #22017

Note: See TracTickets for help on using tickets.
Back to Top