Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21049 closed Bug (fixed)

RuntimeError when running ./manage.py runserver

Reported by: lvella@… Owned by: mburst
Component: Python 3 Version: 1.6-beta-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

Description

This happened to me when I tried to "./manage.py runserver":

$ ./manage.py runserver
Validating models...

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/__init__.py", line 397, in execute_from_command_line
    utility.execute()
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/__init__.py", line 390, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/base.py", line 240, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/base.py", line 283, in execute
    output = self.handle(*args, **options)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/commands/runserver.py", line 75, in handle
    self.run(*args, **options)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/core/management/commands/runserver.py", line 84, in run
    autoreload.main(self.inner_run, args, options)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/utils/autoreload.py", line 181, in main
    reloader(wrapped_main_func, args, kwargs)
  File "/home/vella/projetos/chroni9/venv/site-packages/django/utils/autoreload.py", line 148, in python_reloader
    reloader_thread()
  File "/home/vella/projetos/chroni9/venv/site-packages/django/utils/autoreload.py", line 129, in reloader_thread
    if code_changed():
  File "/home/vella/projetos/chroni9/venv/site-packages/django/utils/autoreload.py", line 60, in code_changed
    for m in sys.modules.values():
RuntimeError: dictionary changed size during iteration

I am using Django 1.6b2, with the totally experimental Python 3 implementation from PyPy 2.1, so I can not be sure if this really is a Django Python 3 issue, just PyPy issue, or PyPy Python 3 issue.

It happened only once, just now, and I was unable to reproduce. I am using SQLite, if that matters...

Change History (8)

comment:1 by Claude Paroz, 11 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

Right, in Python 3 values() returns a dictionary view (http://docs.python.org/3/library/stdtypes.html#dictionary-view-objects), not a copy of the values as in Python 2. Probably wrapping sys.modules.values() inside list() would be sufficient to ensure thread-safety.

comment:2 by mburst, 11 years ago

Owner: changed from nobody to mburst
Status: newassigned

comment:3 by mburst, 11 years ago

The pull request for this ticket is here https://github.com/django/django/pull/1575

comment:4 by mburst, 11 years ago

Has patch: set

comment:5 by Max Burstein <mburst@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 559cb826b850faeb7ad198a3a78a38f07dcf3b42:

Fixed #21049 -- Fixed autoreload for Python 3

Changed th system module values check to return a list.
In Python 3 it returns a dict_view which could occassionally produce
a runtime error of "dictionary changed size during iteration".

comment:6 by Andrew Godwin <andrew@…>, 11 years ago

In ce5e09353d4ac3bda10f95e1cc8e609b0b397fdc:

Merge pull request #1575 from mburst/ticket_21049

Fixed #21049 -- Fixed autoreload for Python 3

comment:7 by Tim Graham <timograham@…>, 11 years ago

In 92e89452f1aa3987cb70648e69718c6adea4b079:

[1.6.x] Fixed #21049 -- Fixed autoreload for Python 3

Changed th system module values check to return a list.
In Python 3 it returns a dict_view which could occassionally produce
a runtime error of "dictionary changed size during iteration".

Backport of 559cb826b8 from master

comment:8 by Claude Paroz <claude@…>, 11 years ago

In e0381cdf2e7f677c5b29f2e3351993e92915569a:

Fixed #22017 -- Prevented RuntimeError on Python 3

Refs #21049. Thanks quinox for the report.

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